开发者

create safe title from string

开发者 https://www.devze.com 2022-12-18 01:32 出处:网络
moving a lot more of my old php functions to 开发者_JS百科jquery alternatives. I\'m a bit stuck on creating a decent preg_match function.

moving a lot more of my old php functions to 开发者_JS百科jquery alternatives. I'm a bit stuck on creating a decent preg_match function.

Is there an easy way to make strings url safe & seo'd?

php;

function superClean($str){

$str = strtolower($str);
$str = str_replace(" ", "-", $str);
$str = preg_replace('/[^a-z0-9_]/i', '-', $str);
$str = preg_replace('/_[_]*/i', '-', $str);
$str = str_replace('---', '-', $str);
$str = str_replace('--', '-', $str);
$str = str_replace('-s-', 's-', $str);

return $str;

}


wow - never used them that much but think they're gonna be really useful for the future!

var String = "My'New ?! 'æ î Hat";
var string = String.toLowerCase();
string = string.replace(/[^a-zA-Z0-9_]/g,'-');
alert(string.replace(/[-]{2,}/,'-'))

thanks Jan!

0

精彩评论

暂无评论...
验证码 换一张
取 消