Jump to content

Help


lizardips

Recommended Posts

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.