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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.