Portal Home > Knowledgebase > Articles Database > Fnction to make a URL friendly title?


Fnction to make a URL friendly title?




Posted by marmoset01, 05-05-2007, 04:57 PM
Does anyone already have a pre-made function to turn a title like the following: into something like Would be much appriciated

Posted by Engelmacher, 05-05-2007, 05:04 PM
Between str_replace and preg_replace you should be able to get something going pretty quickly there.

Posted by marmoset01, 05-05-2007, 09:12 PM
I know, but Im not a pro when it comes to those areas to php. I was hoping for an already made function that does this effectively and cleanly.

Posted by Barti1987, 05-05-2007, 10:22 PM
Peace,

Posted by Jatinder, 05-06-2007, 09:05 AM
azizny you don't need to use the foreach loops. str_replace can accept arrays as parameters. So, you can just use:

Posted by mitchlrm, 05-07-2007, 07:13 AM
If you just need it to work in a URL then how about just:

Posted by avocado, 05-07-2007, 05:38 PM
or, if you want to use hyphens, which are more SEO-friendly:

Posted by marmoset01, 05-07-2007, 11:31 PM
Hyphens are better for SEO? I would never have imagined. Thanks for the help

Posted by Sindre, 05-08-2007, 07:17 AM
Search engines (at least Google) treat hyphens in the same way as spaces, so if you have a page named my-best-page.html it would have equally chance of showing up in the results regardless if the user searched for "my best page" or "my-best-page". If the file was named my_best_page.html you will have to actually include the underscores in the search for it to show up. Oh well, I guess you got the idea

Posted by ak7861, 05-11-2007, 12:17 AM
Hyphens are better for SEO because they are used more often than underscores and thus in search engines you would get more results if you searched the keyword with a hyphen. I personally use underscores since some of my titles require a hyphen by proper grammar.



Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read
Alabanza Host Listing (Views: 699)