Page 1 of 1
preg_match_all
Posted: Tue Mar 07, 2006 6:05 am
by welsh_sponger
I am trying to use this function preg_match_all but am having problems outputting the matches it makes...
So i do the match and then try and print the result...
this simply prints "Array"
Ive also tried...
which again produces "Array[1]"
How do I get it to print the contents of the array?
Thanks for your help
Posted: Tue Mar 07, 2006 9:06 am
by Buddha443556
Really could use some code involving the preg_match_all()?
Code: Select all
print matches[1]; // missing $ here
Posted: Tue Mar 07, 2006 10:15 am
by s.dot
if you want to print an array (which is what you're trying to print) use
print_r()
Posted: Mon Mar 27, 2006 9:07 am
by jito
patrikG | Please use Code: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
hi,
actually it's an array inside an array u r tryin to print, try this:
Code: Select all
foreach($matches as $val)
{
foreach($val as $v1)//as $val itself is an arrary
{
echo $v1."<br>";//now u have the values inside $val array
}
}
Happy programming
patrikG | Please use Code: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Posted: Mon Mar 27, 2006 9:50 am
by patrikG
no need for loops
Code: Select all
echo'<H3>_$matches</H3><pre>';print_r($matches);echo'</pre>';