string issue

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

string issue

Post 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
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Code: Select all

$url = strtr($url, array('/'=>'', 'tickets.html'=>'', '_'=>' ');
$url = trim($url);
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post 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);
Post Reply