note 107112 deleted from function.preg-replace by crell
| From: | crell@php.net | Date: | Fri, 01 Jul 2022 19:49:43 +0000 |
| Subject: | note 107112 deleted from function.preg-replace by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-218864@lists.php.net to get a copy of this message | ||
Note Submitter: hvishnu999 at gmail dot com
----
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