Houdini wrote:Try using this, it works for me
$text ="<a href='http//mysite.com/test.php'>";
$text = preg_replace('/(<img .*?)("|\'| )>/i','<img\\1\\2 />',$text2);
echo $text2;
It still produces the same problems. E.g. <img changes to <img ... /> but <a> also changes to <a /> which is not needed.
Here is my EXACT code in full:
function makeXHTML($text)
{
$text = preg_replace("/<([A-Z]{1,20})(.*?)>/se","'<'.strtolower('\\1').'\\2>'",$text);
$text = preg_replace("/<\/([A-Z]{1,20})>/se","'</'.strtolower('\\1').'>'",$text);
for($do=0;$do!=10;$do++)
$text = preg_replace('/( [a-z,0-9]{1,50})=(?<!")([a-z,0-9]{1,50})( |\/|>)/Si','\\1="\\2"\\3',$text);
[b]$text = preg_replace('/(<img .*?)("|\'| )>/i','<img\\1\\2 />',$text2);[/b]
$text = preg_replace('/<br>/i','<br />',$text);
$text = preg_replace('/<hr>/i','<hr />',$text);
$text = preg_replace('/<font.*?size=(\'|"| )2(\'|"| ).*?>/i','<span class="font12px">',$text);
$text = preg_replace('/<font.*?size=(\'|"| )3(\'|"| ).*?>/i','<span class="font14px">',$text);
$text = preg_replace('/<font.*?>/i','<span class="font10px">',$text);
$text = preg_replace('/<\/font>/i','</span>',$text);
$text = stripslashes($text);
return $text;
}
The line in bold is the line you gave me. I've tried commenting ALL lines out and leaving just that one and it still changes <a> to <a /> so it is definetly that, that is causing the problem.
Thanks for your help.