Hi I'm trying to use preg_replace ucwords strtolower to convert an XML file with 100s of different names in upper case to ucwords strtolower Can't get it to work had a look at the manual but trying to understand the principle of how it works I know this example is incorrect ... eg $filename = "name.xml"; $data = preg_replace("<name>(.*?)</name>", "<name>ucwords (strtolower(.*?));</name>", file_get_contents($filename)); $fp = fopen($filename, "w"); fwrite($fp, $data); fclose($fp); eg <name>JOE BLOGGS</name> <name>FRED JONES</name> to <name>Joe Bloggs</name> <name>Fred Jones</name> Can anyone point me in the right direction? Thanks in advance
Code: <?php $file = "<name>JOE BLOGGS</name>\n". "<name>FRED JONES</name>"; $result = preg_replace('/<name>(.*)<\/name>/Uie', "'<name>'.ucwords(strtolower('$1')).'</name>'", $file); echo htmlentities($result); ?> That's what I came up with just now, obviously it doesn't do all the file handling stuff. EDIT: BTW, I should imagine you'd need to be careful with using the 'e' modifier though. Perhaps a PHP Guru could comment? EDIT2: Why not just parse the XML? If you're using PHP5 it's super easy, if not XML_Serializer might be the easiest way of doing things.
Using XML_Serializer was as an alternative to doing it with regular expressions and the 'e' modifier. Using the 'e' modifier might be a security risk, I'm not entirely sure on this one. *Waits for someone more knowledgeable*