Skip to content

Instantly share code, notes, and snippets.

@mamchenkov
Last active October 10, 2015 02:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mamchenkov/3621188 to your computer and use it in GitHub Desktop.
Save mamchenkov/3621188 to your computer and use it in GitHub Desktop.
Encoding URLs for XML, using regular expressions
<?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