what is the best preg_replace to create an SEOed text to be used in uri ??
i mean like if we had this uri http://t.com/SOME RANDOM $#@ TEXT _ + ?/ =\
, what is best preg_replace expression to clean it up ?
Thank you .
EDIT : assuming y开发者_JS百科ou have multiple languages in the random text language ??
Do you mean a slug?
Slug('SOME RANDOM $#@ TEXT _ + ?/ =\\'); // some-random-text
For that this should be enough:
function Slug($string, $slug = '-')
{
return strtolower(trim(preg_replace('~[^0-9a-z]+~i', $slug, $string), $slug));
}
I guess what you're looking for is URL sanitizing. Here's a link to a filter for php: http://php.net/manual/en/filter.filters.sanitize.php
精彩评论