Mr Chris Posted September 14, 2006 Share Posted September 14, 2006 If I call out:<? php echo $variable; ?>and it calls out [b]a_specific_word[/b] (for example)how can I make it uppercase and get rid of the underscores even if I don't know what text is contained in $variable?Thanks Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 14, 2006 Share Posted September 14, 2006 [code]$variable = strtoupper(str_replace("_","",$variable));[/code] Quote Link to comment Share on other sites More sharing options...
.josh Posted September 14, 2006 Share Posted September 14, 2006 [code]$variable = "a_specific_word";$variable = strtoupper(str_replace('_',' ',$variable));echo $variable;[/code]edit ^^ beated me Quote Link to comment Share on other sites More sharing options...
Mr Chris Posted September 14, 2006 Author Share Posted September 14, 2006 Cheers Guys,But say it's not called $variable?Ie I have several on my page named anything: eg $variable1, $variable2 etc...Is there just anyway I can say make it uppercase and drop the underscore for [b]ALL[/B] variables?ThanksChris Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 14, 2006 Share Posted September 14, 2006 Like this ??[code]<?phpfunction clean($variable) { echo strtoupper(str_replace("_","",$variable));}$abcd = "this_is_lower_case";clean($abcd);?>[/code] Quote Link to comment Share on other sites More sharing options...
Mr Chris Posted September 14, 2006 Author Share Posted September 14, 2006 Thanks, but don't get that - surely you are having to tell the page each variable name, when I just want it to say [b] Ooooh there's a variable, i'll make that uppercase and drop any underscores from that[/b]?ThanksChris Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 14, 2006 Share Posted September 14, 2006 The 'problem' is that somehow the display script needs to know that "this_is_important" is just plain text but another case of "this_is_important" happens to be a variable string so it should be changed to THISISIMPORTANT.Presumably, you already know which bits of text are just text and which bits are actually variables, so instead of echo $banana you would need to echo clean($banana).Does that help? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.