Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Oct 2007
    Posts
    91
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Need help on preg_match pattern.

    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; 02-20-2008 at 12:48 PM.

  • #2
    New to the CF scene
    Join Date
    Feb 2008
    Location
    In your computer
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Have a try with this code:

    PHP 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([a-z0-9_\-])\t/i",$line,$matches);
    echo 
    "$matches[0]<br>";

    The reason why you always get an array type is because you used $matches[0] as subpattern which always creates an array with the found values.

  • #3
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    try to use instead preg_match, this:

    PHP Code:
    $match preg_split("/\t/",$line); 
    best regards


  •  

    Posting Permissions

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