Page 1 of 1

string issue

Posted: Sat Nov 25, 2006 4:04 am
by itsmani1

Code: Select all

$url = 'chicago_bears_tickets.html'; 
	$url = str_replace('/','',$url);
	$url = str_replace('_tickets.html','',$url);
	$url = str_replace('_',' ',$url);
        
        output : chicago bears
Now i want to optimized this code so that i can do this is one or two steps.
is it possible?

thanks

Posted: Sat Nov 25, 2006 6:43 am
by aaronhall

Code: Select all

$url = strtr($url, array('/'=>'', 'tickets.html'=>'', '_'=>' ');
$url = trim($url);

Posted: Sat Nov 25, 2006 11:12 am
by dibyendrah
Similar approach but using different technique

Code: Select all

$array_find = array("/", "_tickets.html", "_");
$array_replace= array("", "", "");
$url = strr_replace($array_find, $array_replace, $url);