Jump to content

Archived

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

Mr Chris

Changing text called out from a DB?

Recommended Posts

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

Share this post


Link to post
Share on other sites
[code]$variable = strtoupper(str_replace("_","",$variable));[/code]

Share this post


Link to post
Share on other sites
[code]

$variable = "a_specific_word";
$variable = strtoupper(str_replace('_',' ',$variable));
echo $variable;
[/code]

edit ^^ beated me

Share this post


Link to post
Share on other sites
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?

Thanks

Chris

Share this post


Link to post
Share on other sites
Like this ??

[code]<?php
function clean($variable) {
    echo strtoupper(str_replace("_","",$variable));
}

$abcd = "this_is_lower_case";
clean($abcd);
?>[/code]

Share this post


Link to post
Share on other sites
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]?

Thanks

Chris

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

×

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.