View Full Version : Preg_match_all Help!

12-27-2007, 06:20 AM
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, $regs, PREG_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:

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

12-27-2007, 08:11 AM
Try this:
$file = file_get_contents('parts_prices.txt');
preg_match_all('~"([^"]*)": { d:"([^"]*?)", p:"([0-9\.]+)", q:"([0-9\.]+)" }~', $file, $regs, PREG_SET_ORDER);
// foreach, or whatever you want to do with the matches