Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 获取Wordpress帖子中的URL列表_Php_Mysql_Wordpress - Fatal编程技术网

Php 获取Wordpress帖子中的URL列表

Php 获取Wordpress帖子中的URL列表,php,mysql,wordpress,Php,Mysql,Wordpress,我需要提取我的Wordpress帖子内容链接中包含的所有具有指定域名的HREF 域名“stackoverflow.com”示例: 有没有办法通过MySQL查询或PHP脚本实现这一点 提前感谢也许我找到了一个解决方案: 创建一个名为“链接”的Wordpress页面 在used theme文件夹中创建一个名为“page links.PHP”的PHP文件,其中包含tis代码: function getUrls($string) { $regex = '/https?\:\/\/[^

我需要提取我的Wordpress帖子内容链接中包含的所有具有指定域名的HREF

域名“stackoverflow.com”示例:

有没有办法通过MySQL查询或PHP脚本实现这一点


提前感谢

也许我找到了一个解决方案:

  • 创建一个名为“链接”的Wordpress页面
  • 在used theme文件夹中创建一个名为“page links.PHP”的PHP文件,其中包含tis代码:

    function getUrls($string)
    {
        $regex = '/https?\:\/\/[^\" ]+/i';
        preg_match_all($regex, $string, $matches);
        return ($matches[0]);
    }
    
    $the_query = new WP_Query('posts_per_page=-1');
    while ($the_query->have_posts())
    {
        $the_query->the_post();
        $_post_id = get_the_id();
        $_post_content = get_post_field( 'post_content', $_post_id);
    
        $urls = getUrls($_post_content);
    
        foreach($urls as $url)
        {
            if (substr($url, 0, 24) == "http://stackoverflow.com")
                echo $url . '<br />';
        }
    
    }
    
    wp_reset_postdata();
    
    函数getURL($string) { $regex='/https?\:\/\/[^\“]+/i'; preg_match_all($regex,$string,$matches); 返回($matches[0]); } $the_query=new WP_query('posts_per_page=-1'); while($the\u query->have\u posts()) { $the_query->the_post(); $\u post\u id=获取\u id(); $\u post\u content=get\u post\u字段('post\u content',$\u post\u id); $urls=getUrls($\发布内容); foreach($url作为$url) { 如果(substr($url,0,24)=”http://stackoverflow.com") 回显$url。“
    ”; } } wp_reset_postdata();
  • 然后调用bowser中的Wordpress页面。
    通过这种方式,所有具有域“stackoverflow.com”的URL“在帖子中找到的内容将被打印。

    Hi,我尝试使用一个PHP脚本来分析循环中的所有帖子,并使用正则表达式获取内容中的URL。”。但是它不太好用……请随意向我们展示代码,这样我们就可以识别出哪里出了问题。这就是
    的工作原理,而不是你给出你的规范,社区为你解决它。