lizardips Posted April 14, 2008 Share Posted April 14, 2008 I currently use <?php echo($state_name); ?> to pull up State names e.g. (North Carolina) How can I edit this so it will pull it up like e.g. (northcarolina)? I am just learing so please take it easy on me. Link to comment https://forums.phpfreaks.com/topic/101049-help/ Share on other sites More sharing options...
Zhadus Posted April 14, 2008 Share Posted April 14, 2008 If you are looking to make it all lower case, use the strtolower() method. $state = strtolower($state); And a simple way to remove all spaces would be using the str_replace() method. $state = str_replace(" ", "", $state); In the future write everything out, one step at a time what you intend to do and need to accomplish, then search the manual: http://www.php.net/docs.php. Link to comment https://forums.phpfreaks.com/topic/101049-help/#findComment-516687 Share on other sites More sharing options...
discomatt Posted April 14, 2008 Share Posted April 14, 2008 well, the easiest way is by using something like this : $state_name = str_replace(" ", "", $state_name); Replaces all spaces with nothing (in other words, removes them) $state_name = strtolower($state_name); Converts the string to lowercase. Alternately, in one line : $state_name = strtolower( str_replace(" ", "", $state_name) ); Link to comment https://forums.phpfreaks.com/topic/101049-help/#findComment-516688 Share on other sites More sharing options...
lizardips Posted April 14, 2008 Author Share Posted April 14, 2008 Thanks for your help. Im still having problems. Im sure all my fault! Im using it to call up a url but its not exactly correct. Here is what I need. http://www.mysite.com/resources/westvirginia/ Im sure Im entering the code incorrectly see below: <li><a href="/resources/<?$state_name = strtolower( str_replace(" ", "", $state_name) ); ?>.php">West Virginia Real Estate Resources</a></li> Link to comment https://forums.phpfreaks.com/topic/101049-help/#findComment-516725 Share on other sites More sharing options...
Zhadus Posted April 14, 2008 Share Posted April 14, 2008 <?php $state_name = strtolower( str_replace(" ", "", $state_name) ); ?> <li> <a href="/resources/<? echo $state_name; ?>.php">West Virginia Real Estate Resources</a> </li> That should work for you and will help you clean it up a little bit. Link to comment https://forums.phpfreaks.com/topic/101049-help/#findComment-516736 Share on other sites More sharing options...
lizardips Posted April 14, 2008 Author Share Posted April 14, 2008 Thank you that worked. One last question, how do I end it so I can use <?php echo($state_name); ?> like is was intended in the first place with capitals and spaces? Link to comment https://forums.phpfreaks.com/topic/101049-help/#findComment-516745 Share on other sites More sharing options...
Zhadus Posted April 14, 2008 Share Posted April 14, 2008 That's pretty simple, you'll just need to introduce a new variable. If you look in the code provided, you are overwriting $state_name. $state_name = "North Carolina"; $formatState = strtolower( str_replace(" ", "", $state_name) ); echo $state_name; // Displays "North Carolina" echo $formatState; // Displays "northcarolina" Link to comment https://forums.phpfreaks.com/topic/101049-help/#findComment-516747 Share on other sites More sharing options...
lizardips Posted April 14, 2008 Author Share Posted April 14, 2008 Zhadus, You rock:) Thanks for all your help. Link to comment https://forums.phpfreaks.com/topic/101049-help/#findComment-516754 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.