How to use hadoop for text file?

How do you use preg_match to search for a string inside of a text file in PHP?

  • I tried to do this but it doesn't work. if (preg_match("/testFile.txt/",$a)) { echo "A match was found."; } else { echo "A match was not found."; } I'm looking to see if a is part of the text file but when i run it won't detect it and says match was not found.

  • Answer:

    First of all, LEARN THE FREAKING PHP LANGUAGE! Secondly (this is where I'll help you), this is how you use the preg_match function: preg_match( 'regular expression', file_get_contents('filename') ); replace 'regular expression' with a regular expression of your choice. The Perl maunal has a great tutorial for how to use them in Perl, and most of the stuff applies to PHP to (although not everything does). replace 'filename' with the name of the file you want to read from.

Mar at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

First you have to load testFile.txt to a variable. I believe readfile is the simplest way to to do this. $var = readfile('testFile.txt'); if (preg_match('/some regex/',$var)) { echo "A match was found."; } else { echo "A match was not found."; }

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.