Highlight String ( 6 Views )
-
I was fooling around today trying to find interesting functions and among them I found highlight_string. My problem is that it does not highlight the string at all when it outputs it; I am running PHP 4.3.3 and I don't have any idea why it isn't working. Does anyone have any information that I may have overlooked? Maybe it doesn't run on a Windows Server? I tried a simple example such as this and it outputted the text all in black.
PHP Code:
<?php highlight_string('echo "hello";'); ?>
(koray, Bermuda)
OHHHH, lol. Now i get it.
(cüneyt, Mozambique)
What do you mean?
PHP Code:
$php = str_replace("$po$text$pc",highlight_string('<?phpp '.trim($text).'?>B', 1),$php); $php = str_replace("<?phpp ", "", $php); $php = str_replace("?>B", "", $php);
That? I threw them in there so it would start the highlighting and that the tags would be unique so I could remove them with ease. A cheap workaround. I think I can figure the rest out. Thanks for your help.
(nil, Slovenia)
Um, where are you getting the extra p and b after the opening php tags?
(yusuf, Palau)
I already have it fixed [img]images/smilies/tongue.gif[/img] Thanks though. I was able to do <?phpp and ?>B and then remove them with
PHP Code:
$php = str_replace("<?phpp ", "", $php); $php = str_replace("?>B", "", $php);
since they are unique and there are no color changes between the extra characters.
I have expanded this to show numberlines. I've using two <DIV> and the only problem I have at the moment is when a line gets too long it jumps down to the next line and I can't create a empty section in the number column to show that it is still part of the same line.
(merve, New Caledonia)
Wait. That will strip out ALL opening and closing php tags. I'm working with substr to fix that.
(pelin, Guinea-Bissau)
Ahh, Thank You VERY much.
(yahya, Somalia)
Got it:
PHP Code:
<?php
$string = highlight_string("<?php function(); ?>", 1);
$string = str_replace("<?php ", "", $string);
$string = str_replace("?>", "", $string);
echo "$string";
?>
(Güliz, Egypt)
Yeah That is what I am currently doing. I am trying to use substr() to rid of the beginning and ending tags I pre-added. NO luck as of now. Any more hints are appreciated :)
(SERHAT, Sao Tome and Principe)
You can set highligh_string() as a variable, then strip away the <?php tags.
(ERCAN , Myanmar)
Quote:
Originally Posted by BlueFire2k5
Yeah, they add <?php and ?> tags to it and then delete them when it's displayed. That's what I do, as does vB.
|
I'll try it, thanks.
(cansu, Korea, Republic of)
Quote:
Originally Posted by BlueFire2k5
You have to have the <?php in front of any and all php code in it as it will think it's html if not.
PHP Code:
highlight_string('<?php echo "hello"; ?>');
|
Hmm, you sure, I don't see any opening and closing php tags in your [ php ] tag.
(emy, Israel)
Quote:
Originally Posted by tmapm
|
Yeah, they add <?php and ?> tags to it and then delete them when it's displayed. That's what I do, as does vB.
(REMZİ, Slovenia)
(APOO, Eritrea)
Oh thank you very much :) Now I just need to write something to place the tags if they aren't there.
(recep, Lesotho)
You have to have the <?php in front of any and all php code in it as it will think it's html if not.
PHP Code:
highlight_string('<?php echo "hello"; ?>');
(neşe , Western Sahara)
Finally found a good way to do it:
PHP Code:
<?php
function phpHighlight ($string) {
if(preg_match("/<\?php/", $string)) {
$php = highlight_string($string, 1);
} else {
$php = highlight_string("<?php " . $string . " ?>", 1);
$php = substr($php, 65, -40);
$php = "<code><font color=\"#000000\">" . $php . "</font></code>";
}
return "$php";
}
echo phpHighlight("function();");
?>
(Ahmet, Gambia)
Related Topics ... (or search in 1.720.883 topics !)
highlight string class (4) highlight a specific part a string? (7) highlight search string problems (1) highlight search string function (6) highlight search string and show possible match by percent (2) how to apply str_replace to entire string except between specific chars in the string (12) response.write(string + variable + string) issue (3) string parsing ignoring html entities in the string. (31) c# string substitution (or: encoding a uri string) (20)
copyright © 2007-2031 Pfodere.COM ( 6 Pfoyihuee Online )
|