drewgg
4/26/2016 - 2:46 PM

Printing and replacing UTF-8 Characters via HEX codes

Printing and replacing UTF-8 Characters via HEX codes

<?php

// Here is a tool for looking up characters:
// http://www.ltg.ed.ac.uk/~richard/utf-8.cgi?input=%C2%A0&mode=char

// "\xC2\xA0" is a "non-breaking space", ie, &nbsp;'s character
$s = "before\xC2\xA0after";

echo $s ."<br>";

// Setting the "u" flag may break this
$s = preg_replace('/\xC2\xA0/','somethingElse',$s);

echo $s;

?>