Hi all,
I've the below code for extracting particular word from each line of the file. The particular word is the first word after a tab in that line and second word is after second tab. When i used the below code, it gives me "Array" word continuously and not my required word from the file. (This Array word is not from the file, its a php given word.) Am i using the right pattern in preg_match as this word will contain a-z,0-9, _ and - in that word. Please help.The words in each line will be as for ex: "test1_WMA_40_v2_128kbps_48kHz_2"

$file1 = "C:\Program Files\Apache Group\Apache2\htdocs\playback_automation_datafile_WMA_48kHz_full.txt";
$lines = file($file1);
foreach($lines as $line_num => $line)
{
//preg_match("/\t([\S| ]+)\t/",$line,$matches[0]);
preg_match("/\t^([a-z0-9_-])\t/",$line,$matches[0]);
echo "$matches[0]<br>";
}

Thanks,
Ramki.

    preg_match('/\t([-\w]+)[^\t]*\t([-\w]+)/', $line, $matches)
    echo "1st word: '".$matches[1]."', 2nd word: '".$matches[2]."'<br />\n";
    
      NogDog wrote:
      preg_match('/\t([-\w]+)[^\t]*\t([-\w]+)/', $line, $matches)
      echo "1st word: '".$matches[1]."', 2nd word: '".$matches[2]."'<br />\n";
      

      Thanks very much NogDog. It worked! Thanks once again.🙂

      RAmki

        Write a Reply...