We have 41 guests online
PHP Scripts arrow Free PHP Tutorials arrow Free PHP Tutorials arrow PHP Tutorials and Examples arrow PHP 
Free PHP Tutorials arrow PHP Tutorials and Examples arrow PHP

Converting page titles to URL friendly titles
User Rating: / 11
PoorBest 

This is the conversion method used by evil walrus to convert script titles to URL titles. Removes all special characters, except hyphens, underscores, periods, commas and forward slashes, which are converted to underscores. Two or more consecutive underscores are converted to a single underscore.

  1. <?php
  2.  
  3. // written by Aaron Hall, evilwalrus.org
  4. // free to use, modify and redistribute without notification
  5.  
  6. $title = "This is a script -- uses PHP/MySQL! __cool!__   ";
  7. $title = ereg_replace("[^A-Za-z0-9_\-\./, ]", "", $title); // remove special characters
  8. $title = str_replace(array('.','-','/',','), " ", $title); // replace legal characters with spaces
  9. $title = trim($title); // remove leading and trailing whitespace
  10. $title = ereg_replace(" {1,}", "_", $title); // convert one or more consecutive spaces to a single underscore
  11. $title = ereg_replace("_{2,}", "_", $title); // convert two or more consecutive underscores to a single underscore
  12.  
  13. echo $title;
  14. // prints "This_is_a_script_uses_PHP_MySQL_cool";
  15.  
  16. ?>

 

 

Directory Stats

There are 1019 listing and 46 categories in our website

Change Language