Skip to content

Instantly share code, notes, and snippets.

@dev-armando
Created November 2, 2021 04:33
Show Gist options
  • Save dev-armando/ccfaf173612b4e352986e592ca0d1cc2 to your computer and use it in GitHub Desktop.
Save dev-armando/ccfaf173612b4e352986e592ca0d1cc2 to your computer and use it in GitHub Desktop.
Funcion para crear urls amigables para PHP
<?php
function urls_amigables($url) {
$url = strtolower($url);
$find = array('á', 'é', 'í', 'ó', 'ú', 'ñ');
$repl = array('a', 'e', 'i', 'o', 'u', 'n');
$url = str_replace ($find, $repl, $url);
$find = array(' ', '&', '\r\n', '\n', '+');
$url = str_replace ($find, '-', $url);
$find = array('/[^a-z0-9\-<>]/', '/[\-]+/', '/<[^>]*>/');
$repl = array('', '-', '');
$url = preg_replace ($find, $repl, $url);
return $url;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment