Jump to content

Archived

This topic is now archived and is closed to further replies.

jberlinsky

preg_replace question

Recommended Posts

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']);

Share this post


Link to post
Share on other sites
[code]
<pre>
<?php
$string = '<img src=BLAH alt=x>';
echo preg_replace('/(<img src=(?:.+?) alt=)x>/', '\1y>', $string);
?>
</pre>
[/code]

Share this post


Link to post
Share on other sites
Or
[code=php:0]preg_replace('/(<img.*?alt=).*?>/is', '\\1y>', $string);[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.