Jump to content


Photo

preg_replace question


  • Please log in to reply
2 replies to this topic

#1 jberlinsky

jberlinsky
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 06 September 2006 - 03:00 PM

I have been TRYING to use preg_replace()...it doesnt give me the right result

OBJECTIVE: change <img src=BLAH alt=x> to <img src=BLAH alt=y>

ATTEMPTED SYNTAX: $post['post'] = preg_replace("/<img src=[(.+?)] alt=x>/","<img src=\\1 alt-y>",$post['post']);

#2 effigy

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

Posted 06 September 2006 - 03:25 PM

<pre>
<?php
	$string = '<img src=BLAH alt=x>';
	echo preg_replace('/(<img src=(?:.+?) alt=)x>/', '\1y>', $string);
?>
</pre>

Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#3 Nicklas

Nicklas
  • Members
  • PipPipPip
  • Advanced Member
  • 111 posts
  • Locationwww.nswardh.com

Posted 06 September 2006 - 03:41 PM

Or
preg_replace('/(<img.*?alt=).*?>/is', '\\1y>', $string);





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users