PHPFront

Home > PHP > URL friendly paths
The PHP website created by its users!



URL friendly paths


Author
DescriptionMake any variable URL friendly by replacing white spaces and converting non-word chars.
RatingThis script has been rated 2/5 (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: ��� &amp;");  // Gives: Weird_chars_too__amp

?>



Rate it: Print Print

Comments


No comments posted yet.

Name
Website
Your comment