Monday, January 27, 2014

PHP replace char with Unicode value inside string


<?php
$originalString = "Pritom K Mondal, 0154785";
function ord2($s2) {
    return "&#" . ord($s2) . ";";
}
echo preg_replace("/[^a-zA-Z0-9]/e", "ord2('\\0')", $originalString) ?>

And output will be as:

Pritom&#32;K&#32;Mondal&#44;&#32;0154785

No comments:

Post a Comment