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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Preg_match_all Help!

    PHP Code:
    foreach($file_lines as $line)
    {
        
    // Interpret Line
        // "792036": { d:"Holmes Heavy Duty Slide Bolt", p:"9.11", q:"1" },

        // Places three space separated words into $regs[1], $regs[2] and $regs[3].
        //ereg("[0-9]{6}", $line, $regs); 
        
    preg_match_all('~"([0-9]{6})": { d:"([^"]+)", p:"([0-9]\.[0-9]{2})", q:"([0-9])" }~'$line$regsPREG_SET_ORDER);
        
        echo 
    $regs[0][1].' ';
            
        echo 
    $line; echo "<br>"

    I am having problems with this preg code. First of all, I am clueless how to do ereg matching, and the preg code is from phpfreaks.com help.

    However, as you can see here:
    http://macaction.org/topsoftweb/test.php

    I am getting results only on certain lines. Can any one give me some pointers?

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Try this:
    PHP Code:
    $file file_get_contents('parts_prices.txt');
    preg_match_all('~"([^"]*)": { d:"([^"]*?)", p:"([0-9\.]+)", q:"([0-9\.]+)" }~'$file$regsPREG_SET_ORDER);
    // foreach, or whatever you want to do with the matches 


  •  

    Posting Permissions

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