SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Oct 2007
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help needed on preg_match pattern choosing.

    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"

    Code:
    $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.
    Last edited by ramki067; Feb 20, 2008 at 06:49.

  2. #2
    SitePoint Guru Ruben K.'s Avatar
    Join Date
    Jun 2005
    Location
    Alkmaar, The Netherlands
    Posts
    693
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're using it wrong.

    put preg_match("/\t^([a-z0-9_-])\t/",$line,$matches); instead, THEN print $matches[0]

  3. #3
    SitePoint Zealot
    Join Date
    Oct 2007
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    its giving the following error,after using preg_match as u said,

    Code:
    Notice: Undefined index: 0 in C:\Program Files\Apache Group\Apache2\htdocs\selected_stream.php on line 124
    Thanks,
    /Ramki.

  4. #4
    SitePoint Guru Ruben K.'s Avatar
    Join Date
    Jun 2005
    Location
    Alkmaar, The Netherlands
    Posts
    693
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That just means that there are 0 matches


Bookmarks

Posting Permissions

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