0

I have a wordpress website, and i wanna execute my php code on my wordpress. my php code does web crawling. Can anyone guide me on how to run my code on wordpress, i've tried using plugins such as insert php, global content blocker and exec-php, but i keep on getting errors.

error message on my wordpress

  <?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){

// echo $page."
"; //} ?>

4
  • stackoverflow.com/questions/18896146/… Commented Apr 10, 2016 at 16:09
  • consider using this method instead Commented Apr 10, 2016 at 16:10
  • The error in the image suggests that you have to rename the function get_links() to something else. It conflicts with another function with the same name. Commented Apr 10, 2016 at 19:17
  • thanks guys, very help full tips Commented Apr 11, 2016 at 13:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.