preg_match_all

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
welsh_sponger
Forum Newbie
Posts: 14
Joined: Fri Feb 03, 2006 7:46 am

preg_match_all

Post 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...

Code: Select all

print matches[1];
this simply prints "Array"

Ive also tried...

Code: Select all

print matches[0][1];
which again produces "Array[1]"

How do I get it to print the contents of the array?

Thanks for your help
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

Really could use some code involving the preg_match_all()?

Code: Select all

print matches[1]; // missing $ here
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

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 »

patrikG | Please use

Code: Select all

and

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

and

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]
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

no need for loops

Code: Select all

echo'<H3>_$matches</H3><pre>';print_r($matches);echo'</pre>';
Post Reply