php - Fatal error: Cannot redeclare parse_external_url() -


i write piece of code in order parse url in web site given input(i choose web site : www.tunisie-web.org ) ,and determinate if there external script php: crawl.php 's contents

       <?php           set_time_limit(10000);       include_once('../phpcrawl_083/phpcrawl_083/libs/phpcrawler.class.php');       class mycrawler extends phpcrawler       {        function handledocumentinfo(phpcrawlerdocumentinfo $docinfo)        {    // detect linebreak output ("\n" in cli-mode, otherwise "<br>").     if (php_sapi == "cli" ) $lb = "\n";    else {     $lb = "<br/>";    function parse_external_url( $url) {    echo "0"."<br/>";    // abort if parameter url empty    if( empty($url) ) {     echo "l'url est vide"."<br/>"; } echo "1"."<br/>";       // parse home url , parameter url      $link_url = parse_url( $url );       $home_url = parse_url( $_server['http_host'] );             //$home_url = parse_url( home_url() );  // works wordpress        // decide on target       if( $link_url['host'] == $home_url['host'] ) {        // internal link        echo "<br/>";       echo "2"."<br/>";        }            else {        // external link        // print url , http-status-code         echo "page requested: ".$url." (".$url->http_status_code.")"."<br/>";         // print refering url         echo "referer-page: ".$url->referer_url."<br/>";        }         echo "3";           }         parse_external_url( $docinfo->url);         echo "<br/>";         flush();           }        }        }      $crawler = new mycrawler();      $crawler->seturl("www.tunisie-web.org ");      $crawler->addreceivecontenttype("#text/html#");     $crawler->addurlfilterrule("#\.(jpg|gif|png|pdf|jpeg|css|js)$# i");      $crawler->setworkingdirectory("c:/users/mayss/documents/travailcrawl/");        $crawler->go();      ?> 

but show me result below

0 1 page requested: http://www.tunisie-web.org () referer-page: 3

and error fatal error: cannot redeclare parse_external_url() (previously declared in c:\wamp\www\crawl\crawl.php:23) in c:\wamp\www\crawl\crawl.php on line 23

this means re-declaring function.

probably have included c:\wamp\www\crawl\crawl.php in function declared or extended class phpcrawler.class.php have same function.

solution:

rename function, declared in mycrawler class, like:

function parse_external_url( $url) {   //======to=========== function parse_external_url2( $url) {   // or other name 

note: suspect want call function parse_external_url in class rather declaring, coz declaring function within function not practice. if so, call properly; if not, declare different name , outside function handledocumentinfo , call function in handledocumentinfo function of class.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -