Working with simple STrings

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
orbstra
Forum Commoner
Posts: 30
Joined: Thu Dec 07, 2006 5:07 pm

Working with simple STrings

Post by orbstra »

Hey I want to edit my string $url..

in this case $url is equal to 'admin/page/add'

I want to change $url to $url_bread and change the string to 'admin >> page >> add'

so to recap: I want to change

'admin/page/add'
for every '/' I want there to be ' >> '

thanks guys
Corvin
Forum Commoner
Posts: 49
Joined: Sun Dec 03, 2006 1:04 pm

Post by Corvin »

http://www.php.net/str_replace

Code: Select all

<?php
$url = "admin/page/add";
$url_bread = str_replace("/", " >> ", $url);
?>
orbstra
Forum Commoner
Posts: 30
Joined: Thu Dec 07, 2006 5:07 pm

Post by orbstra »

Works great! THANKS!

What if I wanted the first letters in $url variable to be capitalized
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

orbstra
Forum Commoner
Posts: 30
Joined: Thu Dec 07, 2006 5:07 pm

Post by orbstra »

That works great, but not completely.. I think this is the best I am going to get, but if it is possible, could I capitalize every first letter?
for instance

Original:

Code: Select all

"admin >> page >> add
With ucfirst():

Code: Select all

"Admin >> page >> add
What I hope is possible to do next:

Code: Select all

"Admin >> Page>> Add
THANKS!

PS: love this php community its been a big help, I will definetly help spread the word
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

orbstra
Forum Commoner
Posts: 30
Joined: Thu Dec 07, 2006 5:07 pm

Post by orbstra »

Wait ignore that one!! Just figured it out

Code: Select all

guav_sys_url_name();
		global $url;
		$url_bread = str_replace("/", " >> ", $url);
		$url_bread = ucwords($url_bread);
		$url_bread = ucwords(strtolower($url_bread));
		echo '<small>' . $url_bread . '</small>';
Post Reply