Created
November 2, 2021 04:33
-
-
Save dev-armando/ccfaf173612b4e352986e592ca0d1cc2 to your computer and use it in GitHub Desktop.
Funcion para crear urls amigables para PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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