Skip to content

Instantly share code, notes, and snippets.

@tieutantan
Created January 14, 2017 15:01
Show Gist options
  • Save tieutantan/8089796d5ed04d3d4fc46f20e487aa68 to your computer and use it in GitHub Desktop.
Save tieutantan/8089796d5ed04d3d4fc46f20e487aa68 to your computer and use it in GitHub Desktop.
Remove non-ascii characters from string in php
<?php
// http://stackoverflow.com/a/8782114
header('Content-Type: text/html; charset=UTF-8');
$str = "abqwrešđčžsff";
$res = preg_replace('/[^\x20-\x7E]/','', $str);
echo "($str)($res)";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment