need this script

Discussion in 'PHP' started by kool002, May 20, 2007.

  1. #1
    Can someone write a script which will read my articles and create a file which has all the words in that article.

    for example
    say article is.

    There is a new gadget by abc company with great features like auto reset....

    I want a file or a table popuplated with words like
    There
    is
    a
    new
    gadget...etc etc

    ... well you get the idea.
     
    kool002, May 20, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    $article = 'There is a new gadget by abc company with great features like auto reset....';
    
    $words = preg_split('/[\s,\.]+/', $article, -1, PREG_SPLIT_NO_EMPTY);
    
    $fp = fopen('article.txt', 'w');
    fwrite($fp, implode("\n", $words));
    fclose($fp);
    
    
    PHP:
     
    nico_swd, May 20, 2007 IP
  3. kool002

    kool002 Peon

    Messages:
    342
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks nico.

    Can someone modify this script to query a mysql table.
    get the article in a variable.
    get all the words.
    insert it into a new table.

    and do this for each article?

    Thank you very much.
     
    kool002, May 20, 2007 IP
  4. kool002

    kool002 Peon

    Messages:
    342
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I am sorry.

    I should have mentioned that I am willing to pay if some one do this job.

    anyone? Please PM
     
    kool002, May 21, 2007 IP
  5. Free Directory

    Free Directory Peon

    Messages:
    89
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You forgot about duplicates:)
    And some of the words should not be used... let say 3 or less characters, no?
    For me seems like a tagging system for articles (if you use count of the words in the new created table)

    the code it's simple:
    use the Nico regexp to extract words (in a loop for all articles extracted from database) then foreach word, a simple insert in database.
    Piece of cake. You can even use the file that's already created, if you change the mod of writing into it from "w" to "a+", and generate insert commands from it:)
     
    Free Directory, May 21, 2007 IP
  6. kool002

    kool002 Peon

    Messages:
    342
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks every one.

    PM me if someone can code it for me.
     
    kool002, May 22, 2007 IP