Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Newbie - PHP String problems
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


Report this thread to moderator Post Follow-up to this message
Old Post
gray
11-16-04 01:55 AM


Re: Newbie - PHP String problems
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 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

Report this thread to moderator Post Follow-up to this message
Old Post
Andy Hassall
11-16-04 01:55 AM


Re: Newbie - PHP String problems

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




Report this thread to moderator Post Follow-up to this message
Old Post
gray
11-16-04 01:55 PM


Re: Newbie - PHP String problems
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)

Report this thread to moderator Post Follow-up to this message
Old Post
Krešo Kunjas
11-17-04 08:58 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP SQL archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:56 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.