Jump to content

[SOLVED] Array help


slpctrl

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/142548-solved-array-help/
Share on other sites

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";
}

 

Link to comment
https://forums.phpfreaks.com/topic/142548-solved-array-help/#findComment-747061
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.