Lautarox Posted October 25, 2010 Share Posted October 25, 2010 I was using the xml_parse() function when I've noticed there are some "&" inside the xml tags, like this <> & </>, I was trying to use preg_replace on it, but I couldn't, I've used the pattern "/<(.*)>(.*)&(.*)</(.*)>/" and the replace string "<$1>$2and$3</$4>"; but it doesn't even print the "<>" . Any suggestions? Thanks in advance Link to comment https://forums.phpfreaks.com/topic/216779-preg_replace-for-xml-correction/ Share on other sites More sharing options...
sasa Posted October 26, 2010 Share Posted October 26, 2010 try <?php $test = ' <blah> <asd & 123> </asd> one & tvo <asd> 1 & 2 & 3</asd> </blah>'; $count=1; while ($count>0) { $test = preg_replace('/(>[^&<]*)&([^<]*<)/s', '\1and\2', $test, 1000, $count); } echo $test; ?> Link to comment https://forums.phpfreaks.com/topic/216779-preg_replace-for-xml-correction/#findComment-1126555 Share on other sites More sharing options...
Lautarox Posted October 27, 2010 Author Share Posted October 27, 2010 Why is it inside a loop? Link to comment https://forums.phpfreaks.com/topic/216779-preg_replace-for-xml-correction/#findComment-1126904 Share on other sites More sharing options...
sasa Posted October 27, 2010 Share Posted October 27, 2010 it replace just one & in same tag and if you have more than one you must use it again Link to comment https://forums.phpfreaks.com/topic/216779-preg_replace-for-xml-correction/#findComment-1126933 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.