Return to Snippet

Revision: 5094
at February 11, 2008 16:03 by evanwalsh


Initial Code
<?php

function str2url($title,$sep = "-"){
	$exclude = array("!","@","#","$","%","^","&","*","(",")","=","{","}","[","]","|","\\","/","?","<",">","~","`","_","+","=","-");
	$pieces = explode(' ',str_replace($exclude,"",strtolower($title)));
	$output = NULL;
	foreach($pieces as $key => $val){
		if($pieces[$key+1] == NULL){
			$sep = NULL;
		}
		$output .= $val.$sep;
	}
	return $output;
}

echo str2url("Evan Walsh Rocks"); // returns evan-walsh-rocks

?>

Initial URL
http://nothingconcept.com

Initial Description

                                

Initial Title
Make string into post slug

Initial Tags
url, php, post, convert

Initial Language
PHP