Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.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
在wordpress上执行php_Php_Wordpress - Fatal编程技术网

在wordpress上执行php

在wordpress上执行php,php,wordpress,Php,Wordpress,我有一个wordpress网站,我想在我的wordpress上执行我的php代码。我的php代码执行web爬行。有谁能指导我如何在wordpress上运行我的代码吗?我曾尝试使用insert php、global content blocker和exec php等插件,但我不断出错 <?php $to_crawl ="http://eklas.msu.edu.my.com"; $c = array(); function get_links($url) { global $c; $

我有一个wordpress网站,我想在我的wordpress上执行我的php代码。我的php代码执行web爬行。有谁能指导我如何在wordpress上运行我的代码吗?我曾尝试使用insert php、global content blocker和exec php等插件,但我不断出错

  <?php

$to_crawl ="http://eklas.msu.edu.my.com";
$c = array();

function get_links($url) {
global $c;
$input = @file_get_contents($url);
$regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>";
preg_match_all("/$regexp/siU",$input,$matches);
$base_url = parse_url($url, PHP_URL_HOST);
$l = $matches[2];

foreach($l as $link){

    if (strpos($link, "#")){
        $link = substr($link, 0, strpos($link, "#"));   
    }

    if (substr($link,0,1) == ".") {
        $link = substr($link, 1);
    }

    if (substr($link, 0, 7)== "http://"){
            $link = $link;
        }else if (substr($link, 0, 8)== "https://"){
            $link = $link;
        }else if (substr($link, 0, 2)== "//"){
            $link = substr($link, 2);
        }else if (substr($link, 0, 1)== "#"){
            $link = $url;
        }else if (substr($link, 0, 7)== "mailto:"){
            $link = "[".$link."]";
        } else{
            if (substr($link, 0, 1) != "/") {
                $link = $base_url."/".$link;
            } else {
                $link = $base_url.$link;
            }
        }

        if (substr($link, 0, 7) != "http://" && substr($link, 0, 8) != "https://" && substr($link, 0, 1) != "["){
            if (substr($url, 0, 8) == "https://") {
                $link = "https://".$link;
            }else {
                $link = "http://".$link;
            }
        }


        //echo $link."<br />";
        if (!in_array($link, $c)){
            array_push($c, $link);
        }
    }   
}

get_links($to_crawl);

foreach ($c as $page){
//get_links($page);
echo $page."<br />";
}

//foreach ($c as $page){


考虑使用此方法,而不是使用此方法。图像中的错误表明必须将函数get_links()重命名为其他名称。它与另一个同名函数冲突。谢谢大家,非常有用的完整提示