For Programmers: Free Programming Magazines  


Home > Archive > PHP SQL > November 2004 > Newbie - PHP String problems









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Newbie - PHP String problems
gray

2004-11-15, 8:55 pm

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

Andy Hassall

2004-11-15, 8:55 pm

On 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 entirely
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
gray

2004-11-16, 8:55 am



>$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 entirely
>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.



Krešo Kunjas

2004-11-17, 3:58 pm

On 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)
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com