slpctrl Posted January 26, 2009 Share Posted January 26, 2009 Alright, I used the preg_match_all function, and I need to store the number of variables it returns, and then print in plain text all of it's variables. It's something like this: <?php $results = preg_match_all("|<li class=g><h3 class=r><a href=\"(.*)\" class=l(.*)>|U", $result, $matches); $i = 0 while ($i <= $results) { echo $matches[1][$results]; $i++; } ?> Something like that, if you can understand what I'm trying to do, but I can't get it to work. Any suggestions? Quote Link to comment Share on other sites More sharing options...
Cosizzle Posted January 26, 2009 Share Posted January 26, 2009 the problem is that your saying while i is less than or equal to $results. $results isnt a number. Take a look at http://ca.php.net/preg_match_all they use a foreach loop in there. $html = "<b>bold text</b><a href=howdy.html>click me</a>"; preg_match_all("/(<([\w]+)[^>]*>)(.*)(<\/\\2>)/", $html, $matches, PREG_SET_ORDER); foreach ($matches as $val) { echo "matched: " . $val[0] . "\n"; echo "part 1: " . $val[1] . "\n"; echo "part 2: " . $val[3] . "\n"; echo "part 3: " . $val[4] . "\n\n"; } Quote Link to comment Share on other sites More sharing options...
slpctrl Posted January 26, 2009 Author Share Posted January 26, 2009 Yeah, for some reason I thought that foreach didn't work with multi dimensional arrays, I've got it though <?php foreach($matches[1] as $match) { echo "$match<br />"; } ?> Works just fine . Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.