Posted By

DaveChild on 10/15/08


Tagged

url php rewrite


Versions (?)


Advertising

Submit Site


Who likes this?

1 person has marked this snippet as a favorite

karindalziel


PHP Generate URL From Text


Published in: PHP 






URL: http://www.addedbytes.com

Function replaces all non-alpha-numeric chars and cleans up a text string. Should output a usable URL for almost all text.

Expand | Embed | Plain Text
  1. function generate_url_from_text($strText) {
  2. $strText = preg_replace('/[^A-Za-z0-9-]/', ' ', $strText);
  3. $strText = preg_replace('/ +/', ' ', $strText);
  4. $strText = trim($strText);
  5. $strText = str_replace(' ', '-', $strText);
  6. $strText = preg_replace('/-+/', '-', $strText);
  7. $strText = strtolower($strText);
  8. return $strText;
  9. }

Report this snippet 

You need to login to post a comment.

Download royalty free graphics