note 107112 added to function.preg-replace
| From: | hvishnu999 at gmail dot com | Date: | Sun, 08 Jan 2012 14:25:05 +0000 |
| Subject: | note 107112 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-185458@lists.php.net to get a copy of this message | ||
To covert a string to SEO friendly, do this:
$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
----
Server IP: 69.147.83.197
Probable Submitter: 106.79.99.145
----
Manual Page -- http://www.php.net/manual/en/function.preg-replace.php
Edit -- https://master.php.net/note/edit/107112
Del: integrated -- https://master.php.net/note/delete/107112/integrated
Del: useless -- https://master.php.net/note/delete/107112/useless
Del: bad code -- https://master.php.net/note/delete/107112/bad+code
Del: spam -- https://master.php.net/note/delete/107112/spam
Del: non-english -- https://master.php.net/note/delete/107112/non-english
Del: in docs -- https://master.php.net/note/delete/107112/in+docs
Del: other reasons-- https://master.php.net/note/delete/107112
Reject -- https://master.php.net/note/reject/107112
Search -- https://master.php.net/manage/user-notes.php