Page 1 of 1

Adding a \ to an <img tag

Posted: Wed Jul 07, 2004 10:16 am
by Grim...
Okay, if my users are inserting some text, and they want to add an image, they can just do it with html, ie:

Code: Select all

<img src="bob.jpg">
How can I automatically go through their post string and make that into

Code: Select all

<img src="bob.jpg" \>
I assume it's to do with preg_something but I'm no good at that :(

Also, it there a way to add a default alt tag if it hasn't already got one, ie:

Code: Select all

<img src="bob.jpg" alt="Image" \>

Posted: Wed Jul 07, 2004 10:44 am
by Grim...
Okay, I sussed the first bit out myself, it's

Code: Select all

<?php
$string = preg_replace("/<img(.+?)>/", "<img $1 />", $string);
?>