Jump to content


Photo

php preg_match problem


  • Please log in to reply
3 replies to this topic

#1 fareforce

fareforce
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 19 September 2006 - 04:35 AM

I am having problems with a preg_match. The bit of code I need to match up is:
document.images['picture'].src = "images/" + Views[View] + "3.png";

The code I tried is, but it didn't work:
preg_match("|src = \"images/\" + Views[View] + \"(.*).png\"|Uis",get_put($url_aurora),$aurora);

I am not very good with php code so I am sure I messed something up. Can anyone help me? Another line of code I could pull this from would be:
document.write ('3.png" border="0">');


Any help would be greatly appriciated!  =)


#2 btherl

btherl
  • Staff Alumni
  • Advanced Member
  • 3,893 posts
  • LocationAustralia

Posted 19 September 2006 - 07:20 AM

There's a specific forum for regex questions..

I think your problem here is that "+" is a metacharacter.  You need to use \+ if you want to match an actual + sign.  "[" and "]" also need to be escaped, as \[ and \].  The rest looks ok to me

#3 fareforce

fareforce
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 19 September 2006 - 08:21 PM

Ok. I tried using:
preg_match("|src = \"images/\" \+ Views\[View\] \+ \"(.*)\.png\"|Uis",get_put($url_aurora),$aurora);
but it still isn't working.

I guess I should also add the 3 (in the above example) is the variable I am pulling. It can range from 0-10.

#4 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 20 September 2006 - 01:59 AM

Works OK for me. Check your input.
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users