File handling using PHP

Discussion in 'PHP' started by sudip03, Jun 21, 2010.

  1. #1
    I have a .txt file with some content in it. Now i want to search a particular word from it not a letter.

    Say, PHP has evolved as a powerful open-source programming language and used for building web applications..

    Now i want to search the word programming from the entire text using PHP. How to do it.
     
    sudip03, Jun 21, 2010 IP
  2. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #2
    An example to do that:

    
    <?php
    $file_content = file_get_contents("file.txt");
    
    if(preg_match("/programming/",$file_content)){
        echo("Found!");
    }else{
        echo("Not Found!");
    }
    ?>
    
    Code (markup):
     
    s_ruben, Jun 21, 2010 IP