Skip to content

Instantly share code, notes, and snippets.

@devluis
Created December 12, 2014 20:54
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 devluis/eed79da548c2406097d9 to your computer and use it in GitHub Desktop.
Save devluis/eed79da548c2406097d9 to your computer and use it in GitHub Desktop.
Replace special chars in php
<?php
$stringOriginal = "Este string contiene acentos, ÁFRICA, MÉXICO, ÍNDICE, CANCIÓN y NÚMERO.";
$specialChars = array("á", "é", "í", "ó", "ú", "Á", "É", "Í", "Ó", "Ú", "ñ", "Ñ");
$replacementChars = array("a", "e", "i", "o", "u", "A", "E", "I", "O", "U", "n", "N");
$replacedString = str_replace($specialChars, $replacementChars, $originalString);
print $replacedString; // output 'Este string contiene acentos, ÁFRICA, MÉXICO, ÍNDICE, CANCIÓN y NÚMERO.'
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment