Posted By

jdstraughan on 08/14/08


Tagged

regex php seo


Versions (?)

Who likes this?

22 people have marked this snippet as a favorite

jdstraughan
sumandahal
luman
wizard04
bjarkebech
nb109
vali29
ignace
mister
kijan
ninjacharlee
dhavalpatel
mfigge
metthyn
uberdragon
voove
Envo
alberfp
ApeWare
ringo380
Priestd09
tux-world


Make page titles seo-friendly for URL


 / Published in: PHP
 

If you have a title, for something like a blog or product, and want to make an seo-friendly name to call it, here is a function.

SAMPLE INPUT: $title = "This foo's bar is rockin' cool!"; echo makeseoname($title); //RETURNS: //this-foos-bar-is-rockin-cool

  1. function make_seo_name($title) {
  2. return preg_replace('/[^a-z0-9_-]/i', '', strtolower(str_replace(' ', '-', trim($title))));
  3. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: jdstraughan on August 14, 2008

snipplr's version of this removes dashes from the title (see URL in your browser for example! Thx to section31, this one leaves dashes and underscores intact.

Posted By: bjarkebech on February 19, 2009

Great, just what i needed! Thanks a lot :)

Posted By: peterschink on June 22, 2009

Great. And now for the german SEOs...

function makeseoname($title) { $title = pregreplace('/ä/', 'ae', $title); $title = pregreplace('/ö/', 'oe', $title); $title = pregreplace('/ü/', 'ue', $title); $title = pregreplace('/ß/', 'ss', $title); return pregreplace('/[^a-z0-9-]/i', '', strtolower(str_replace(' ', '-', trim($title)))); }

Posted By: seo on November 9, 2009

Thanks for this l was looking for this for my seo companies blog

You need to login to post a comment.