发新话题
打印

函数:preg_replace()

To covert a string to SEO friendly, do this:

<?php
$realname
=
"This is the string to be made SEO friendly!"

$seoname = preg_replace('/\%/',' percentage',$realname
);
$seoname = preg_replace('/\@/',' at ',$seoname
);
$seoname = preg_replace('/\&/',' and ',$seoname
);
$seoname = preg_replace('/\s[\s]+/','-',$seoname);   
// Strip off multiple spaces
$seoname = preg_replace('/[\s\W]+/','-',$seoname);   
// Strip off spaces and non-alpha-numeric
$seoname = preg_replace('/^[\-]+/','',$seoname);
// Strip off the starting hyphens
$seoname = preg_replace('/[\-]+$/','',$seoname);
// // Strip off the ending hyphens
$seoname = strtolower($seoname
);

echo
$seoname
;
?>

This will print: this-is-the-string-to-be-made-seo-friendly
[ 本帖最后由 xiexie 于 2012-3-20 23:05 编辑 ]

TOP

发新话题