Last active
October 10, 2015 02:48
-
-
Save mamchenkov/3621188 to your computer and use it in GitHub Desktop.
Encoding URLs for XML, using regular expressions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# | |
# Encoding URLs for XML, using regular expressions | |
# | |
# XML string | |
$string = '<page>some&page</page><page>some&otherpage</page><page>yet&anotherpage</page>'; | |
$result =preg_replace_callback( | |
'#(<page>(.*?)</page>)#', | |
create_function( | |
'$matches', | |
'return "<page>" . htmlentities($matches[2]) . "</page>";' | |
), | |
$string | |
); | |
print $result; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment