Categories
Web Development

Create SEO Friendly urls with this Slugify PHP Method

	/**
	 * slugify
	 * @param string $str
	 * @return mixed
	 *
	 * Converts nasty URLs to clean, SEO friendly ones
	 */
	public function slugify($str) {
	    $clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $str);
		$clean = strtolower(trim($clean, '-'));
		$clean = preg_replace("/[\/_|+ -]+/", '-', $clean);
		return $clean;
	}

 

Leave a Reply