Code Comments
Programming Forum and web based access to our favorite programming groups.I am using PHP 4.3.4 MySQL 4.0.17 apache 2.0.48 I know these have probably been aswered all before, but I have scoured the internet, with no success. 1 - A string has been generated from a Mysql database, that is going to be echo'd to the screen. But I need to highlight a few words ie <b>text</b>. But in using $mytext = str_replace("text", "<b>text</b>", $text); It does not work. I assume because of the / . So how do I get over it ??? 2 - Similarly I need to change the font colour, but it does not like <font color="#FF0000"> I presume its the # it does not like. TIA
Post Follow-up to this messageOn Mon, 15 Nov 2004 19:53:01 GMT, gray <agenr@agent.com> wrote: >I am using PHP 4.3.4 MySQL 4.0.17 apache 2.0.48 > >I know these have probably been aswered all before, but I have scoured >the internet, with no success. > >1 - > >A string has been generated from a Mysql database, that is going to be >echo'd to the screen. But I need to highlight a few words ie ><b>text</b>. But in using > > $mytext = str_replace("text", "<b>text</b>", $text); > >It does not work. I assume because of the / . "Does not work" is unhelpful - what does it do? What makes you think the / is an issue? <?php $text = "blah text blah text more blah"; $mytext = str_replace("text", "<b>text</b>", $text); print $mytext; ?> Output: blah <b>text</b> blah <b>text</b> more blah So it does work. >2 - > >Similarly I need to change the font colour, but it does not like ><font color="#FF0000"> > >I presume its the # it does not like. Computers can't "like" things. What does it do that you weren't expecting? What makes you think the # is a problem? <font> is deprecated in favour of CSS, but <font color="#FF0000"> is entirel y valid for changing font colour to red. http://www.w3.org/TR/html4/present/....html#edef-FONT -- Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk> <http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Post Follow-up to this message
>$mytext = str_replace("text", "<b>text</b>", $text);
>print $mytext;
Yes got it to work, must have been my typing.
But how can I get it to change TEXT Text tExt etc etc
>
> <font> is deprecated in favour of CSS, but <font color="#FF0000"> is entir
ely
>valid for changing font colour to red.
>
$mytext = str_replace("text", "<font color="#FF0000">text</f>",
$text);
Tried the above but the browser just hangs up with a blank screen.
I found the answer as being
$mytext = str_replace("text", "<font color=\"#FF0000\">text</f>",
$text);
I now it was a silly mistake.
Post Follow-up to this messageOn Tue, 16 Nov 2004 12:26:30 GMT, gray wrote: > > Yes got it to work, must have been my typing. > > But how can I get it to change TEXT Text tExt etc etc use str_ireplace instead of str_replace ( case insesitive version of str_replace)
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.