Simple but wierd PCRE problem...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
kaisellgren
DevNet Resident
Posts: 1675
Joined: Sat Jan 07, 2006 5:52 am
Location: Lahti, Finland.

Simple but wierd PCRE problem...

Post by kaisellgren »

Hi,

My PCRE:

Code: Select all

$content = "function function function hu function";
preg_match("/function/",$content,$matches);
echo = count($matches);
And it echoes 1 ! Why doesn't it echo 4?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

preg_match() simply looks for a single match, nothing more. You want preg_match_all().
User avatar
kaisellgren
DevNet Resident
Posts: 1675
Joined: Sat Jan 07, 2006 5:52 am
Location: Lahti, Finland.

Post by kaisellgren »

Thank you mister feyd I'll try that one :)
Post Reply