bug in the regular expression

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
jasongr
Forum Contributor
Posts: 206
Joined: Tue Jul 27, 2004 6:19 am

bug in the regular expression

Post by jasongr »

Hello people

I would like to use regular expression to check if a string contains the definition of background-image:url(<file>.png) attribute

that is in the following strings the attribute will be found:
style="background-image: url('test.png')"
style="background-image: url('/Folder/test.png')"
style="background-image: url('./folder/Test.png')"

I tried the following but it doesn't work:

Code: Select all

preg_match_all('/background-image:\s*url\(''(.*\.png)''\);/Uis',$s, $matches);
However count($matches[0]) is always zero

can anyone see what is wrong with the regular expression, or maybe something is wrong in my examples

thanks
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

i see a semi colon in your pattern, but not in the examples

you could make it optional by putting a question mark after it eg
;?

also, for debugging, try print_r($matches);

that way you see everything it matched.
jasongr
Forum Contributor
Posts: 206
Joined: Tue Jul 27, 2004 6:19 am

Post by jasongr »

thanks for the suggestion
I will implement it
Post Reply