Re: str_replace question
| From: | Erwin | Date: | Mon, 02 Sep 2002 09:32:23 +0000 |
| Subject: | Re: str_replace question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-114887@lists.php.net to get a copy of this message | ||
> Hello, i have array $reserved_words which i want to replace with bold
> .. but when i tried to do str_replace($reserved_words,
> "<b>".$reserved_words."</b>", $string) it showed Array instead
> of
> <b>word</b>
> if i simply do str_replace($reserved_words, $reserved_words,
> $string) then it shows the words not Array but not in bold ;)
> I know i could use 2 arrays one with bold words one without or i
> could use foreach but i want a simpler solution :)... Any suggestions
That does make sence.
You try to append <b> and prepend </b> to an array, which will (of course)
be converted to string then. Result is that you're call to the str_replaced
function can also be written as:
str_replace( $reserved_words, '<b>Array</b>', $string )
which is definitely not what you want!
You have two options:
a) Create another array of reserved_words, only then appended and prepended
with <b> and </b>
b) Use the code from Olinux
Option B sounds best to me ;-))
HTH
Erwin