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 Quote 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; ?> Quote 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? Quote 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 Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.