|
URL friendly paths
| Author | |
| Description | Make any variable URL friendly by replacing white spaces and converting non-word chars. |
| Rating | (15 votes) |
PHP Code
<? php
function makeUrlFriendly($input) {
// Replace spaces with underscores
$output = preg_replace("/s/e" , "_" , $input);
// Remove non-word characters
$output = preg_replace("/W/e" , "" , $output);
return $output;
}
// Example useage:
echo makeUrlFriendly("I'm some really long title !!1"); // Gives: Im_some_really_long_title_1
echo makeUrlFriendly("Weird chars too: ��� &"); // Gives: Weird_chars_too__amp
?>
Comments
No comments posted yet.
|