Any questions involving matching text strings to patterns - the pattern is called a "regular expression."
Moderator: General Moderators
welsh_sponger
Forum Newbie
Posts: 14 Joined: Fri Feb 03, 2006 7:46 am
Post
by welsh_sponger » Tue Mar 07, 2006 6:05 am
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
Buddha443556
Forum Regular
Posts: 873 Joined: Fri Mar 19, 2004 1:51 pm
Post
by Buddha443556 » Tue Mar 07, 2006 9:06 am
Really could use some code involving the preg_match_all()?
Code: Select all
print matches[1]; // missing $ here
s.dot
Tranquility In Moderation
Posts: 5001 Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana
Post
by s.dot » Tue Mar 07, 2006 10:15 am
if you want to print an array (which is what you're trying to print) use
print_r()
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
jito
Forum Commoner
Posts: 85 Joined: Sat Mar 25, 2006 4:32 am
Location: india
Post
by jito » Mon Mar 27, 2006 9:07 am
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]
patrikG
DevNet Master
Posts: 4235 Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK
Post
by patrikG » Mon Mar 27, 2006 9:50 am
no need for loops
Code: Select all
echo'<H3>_$matches</H3><pre>';print_r($matches);echo'</pre>';