Page 1 of 1
highlight_string problem
Posted: Sun May 23, 2004 5:21 pm
by Steveo31
Hey all... I'm pulling some code out of a mysql DB and trying to highlight it. Not workin, heh...
I put it in the DB with htmlspecialchars and I can pull it out and echo it just fine. However, I must be using highlight_string the wrong way because it won't show the colors.
Code: Select all
$sql = mysql_query("SELECT title, author, body, hits, rating FROM code LIMIT 0,5");
$row = mysql_fetch_assoc($sql);
$code = nl2br($row['body']);
$code2 = highlight_string($code);
Isn't working. Won't even show parse stuff like > to >.
I've read the manual
Thanks.
Posted: Sun May 23, 2004 5:23 pm
by Illusionist
since your selecting more than just one recod, should you be doing:
Code: Select all
$sql = "SELECT title, author, body, hits, rating FROM code LIMIT 0,5";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)){
//$code = nl2br($row['body']); //you don't want this... but if you want to see a bunch of <br /> tags, than gofor it!
highlight_string($code);
}
Re: highlight_string problem
Posted: Sun May 23, 2004 5:30 pm
by jason
Steveo31 wrote:
Isn't working. Won't even show parse stuff like > to >.
It doesn't convert > to >. That means if you have <?php instead of <?php, it won't hightlight correctly.
Posted: Sun May 23, 2004 5:31 pm
by jason
Illusionist wrote:and then you echo code2??
No.
Reread [php_man]highlight_string[/php_man]. You don't have to echo anything, you just output it unless you explicitly ask it to return a value.
Posted: Sun May 23, 2004 5:34 pm
by Illusionist
i just realized that!
Re: highlight_string problem
Posted: Sun May 23, 2004 7:37 pm
by Steveo31
jason wrote:Steveo31 wrote:
Isn't working. Won't even show parse stuff like > to >.
It doesn't convert > to >. That means if you have <?php instead of <?php, it won't hightlight correctly.
Yeah I know it doesn't convert, but without it the data is parsed correctly. With it, they aren't converted.
Anywho, it works if the data in the DB is not htmlspecialchar'd.
Thanks.