Find the answer to your Linux question:
Results 1 to 2 of 2
Hi, I just want to copy the content from Wikipedia. Daily i want to do it. But this should be done automatically. can anyone tel me how to do this ...
  1. #1
    Linux User
    Join Date
    Aug 2008
    Location
    Trichy,India
    Posts
    308

    How to copy the article from wiki using php

    Hi,
    I just want to copy the content from Wikipedia. Daily i want to do it. But this should be done automatically. can anyone tel me how to do this in php? is there any function to copy the content of any article?
    Thanks in advance...

  2. #2
    Linux Newbie
    Join Date
    Dec 2009
    Posts
    241
    You will need a little more ...
    like:
    fopen
    fread / fget
    str_replace
    stristr
    strip_tags

    And another Tip:
    "\n" will produce a new line.

    A example would be:
    PHP Code:
    $page fopen("http://blabla.net?info=2wq""r");
    $echo false;
    $start=explode("\n""Headline1
    Headline2
    Headline3"
    );
    $stop[] = "</h4>";
    while ((
    $line fget($page))!=""){
       if (
    $echo) foreach ($stop as $search
        if (
    stristr($line$search) != false) {
         
    $echo false;
        }
       if (!
    $echo) foreach ($start as $search
        if (
    stristr($line$search) != false) {
         
    $echo true;
        }
     if (
    $echo) {
       
    $line str_replace("<br>""\n"$line);  //<br> marks a newline
           // ... other replacements ... of html tags
       
    $line str_replace("</td>""\t"$line);  //</td> marks end of cell in table
       
    $line str_replace("</tr>""\n"$line);  // </tr> marks end of row in table
       
    $line strip_tags($line);
       echo 
    $line;
     }
    }
    fclose($page); 
    you would write the info like that into a file:
    Code:
    php example.php > filename.txt 2>/dev/null
    an example on howto run this in time intervals would be a crontab entry

    Hope that works ... haven't tried ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...