Created
July 24, 2009 11:31
-
-
Save DaveChild/154025 to your computer and use it in GitHub Desktop.
Generate a URL portion or alias from any text - uses alphanumeric characters and hyphens only.
This file contains hidden or 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 generate_url_from_text($strText) { | |
$strText = preg_replace('/[^A-Za-z0-9-]/', ' ', $strText); | |
$strText = preg_replace('/ +/', ' ', $strText); | |
$strText = trim($strText); | |
$strText = str_replace(' ', '-', $strText); | |
$strText = preg_replace('/-+/', '-', $strText); | |
$strText = strtolower($strText); | |
return $strText; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment