Hi i am having a problem replacing some plain text with colored text, I found this easy when using one word but once i started allowing the input of arrays it stoped working, been debuging for hours with no luck.
My code is:
while ($row=mysql_fetch_assoc($primary))
{
extract($row);
$high = "hello world";
$include = get_include_contents("includes/'$thread'.inc");
$getval = explode(" ", $high);
$lowarray = implode(", ", $getval);
$reparray = implode("</font></b>, <b><font color='00FF00'>", $getval);
$highcont = str_replace("$lowarray", "<b><font color='00FF00'>$reparray</font></b>", $include);
$highsub = str_replace("$lowarray", "<b><font color='00FF00'>$reparray</font></b>", $subject);
print "<table width='700' border='1' bordercolor='#000000' cellpadding='0' cellspacing='0' align='center'>";
Print "<tr>";
print "<td width='500' bgcolor='000000'><font color='FFFFFF'><b>Subject:</b> $highsub</font></td><td width='200' bgcolor='000000'><font color='ffffff'><b>Posted by:</b> $author</font></td>";
print "</tr><tr>";
print "<td colspan='2'>$highcont</td>";
print "</tr><tr>";
print "<form enctype='multipart/form-data' method='post' action='viewtopic.php'><td bgcolor='000000'><font color='ffffff'><b>Date Posted:</b> $posted</font></td><td align='right' bgcolor='000000'><INPUT type=hidden name=thread VALUE='$subject'><INPUT type='image' src='images/comments.gif' alt='Read Comments' name='submit'></td></form>";
print "</tr></table>";
print "<br>";
}
from my understanding this should brak "hello world" into hello and world
Then make an array lookign like this $lowarray = (hello, world)
Then another like this $reparray = (hello</font></b>, <b><font color='00FF00'>world)
when put back into my str_replace array which has the other half the green code included should then look like
$replace = str_replace("hello, world", "<b><font color='00FF00'>hello</font></b>, <b><font color='00FF00'>world</font></b>", $input)
i dont get why once this is made up it doesnt add the coloring code to all fo my occurances, but im new to this and not sure my way of thinking is the best way to do things.
anybody got an idea?
more complex text replaces
Moderator: General Moderators
Re: more complex text replaces
Code: Select all
$replace = str_replace("hello, world", "<b><font color='00FF00'>hello</font></b>, <b><font color='00FF00'>world</font></b>", $input);The syntax you want is
Code: Select all
$replace = str_replace(
array("hello", "world"),
array("<b><font color='00FF00'>hello</font></b>", "<b><font color='00FF00'>world</font></b>"),
$input);Also: when giving the color in hex you need to put a # in front:
Code: Select all
<font color='#00FF00'>-
Grahamhart
- Forum Commoner
- Posts: 27
- Joined: Wed Jun 11, 2008 6:05 am
Re: more complex text replaces
hehe font will be replaced out once i apply the style sheets, just trying to learn some php atm tho
Thanks for the tips