We Recommend

Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems
Wicked Cool PHP contains a wide variety of scripts to process credit cards, check the validity of email addresses, template HTML, and serve dynamic images and text.


Posted By

DaveChild on 10/15/08


Tagged

url php rewrite


Versions (?)


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.

  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.