Highlight String ( 6 Views )

no kitty!
  1. 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)

  2. OHHHH, lol. Now i get it.

    (cüneyt, Mozambique)

  3. What do you mean?
    PHP Code:

    $php = str_replace("$po$text$pc",highlight_string('<?phpp '.trim($text).'?>B', 1),$php);
    $php = str_replace("&lt;?phpp ", "", $php);
    $php = str_replace("?&gt;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)

  4. Um, where are you getting the extra p and b after the opening php tags?

    (yusuf, Palau)

  5. 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("&lt;?phpp ", "", $php);
    $php = str_replace("?&gt;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)

  6. Wait. That will strip out ALL opening and closing php tags. I'm working with substr to fix that.

    (pelin, Guinea-Bissau)

  7. Ahh, Thank You VERY much.

    (yahya, Somalia)

  8. Got it:
    PHP Code:

    <?php
    $string
    = highlight_string("<?php function(); ?>", 1);
    $string = str_replace("&lt;?php&nbsp;", "", $string);
    $string = str_replace("?&gt;", "", $string);
    echo
    "$string";
    ?>


    (Güliz, Egypt)

  9. 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)

  10. You can set highligh_string() as a variable, then strip away the <?php tags.

    (ERCAN , Myanmar)

  11. 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)

  12. 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)

  13. Quote:

    Originally Posted by tmapm
    I'm experimenting some more and I was wondering how it was possible to have it highlight PHP tags even without the opening <?php and closing ?>. Something that would work like this: http://www.cheetah-soft.com/clib/fun..._highlight.php

    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)

  14. I'm experimenting some more and I was wondering how it was possible to have it highlight PHP tags even without the opening <?php and closing ?>. Something that would work like this: http://www.cheetah-soft.com/clib/fun..._highlight.php

    (APOO, Eritrea)

  15. Oh thank you very much :) Now I just need to write something to place the tags if they aren't there.

    (recep, Lesotho)

  16. 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)

  17. 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 )

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 
0.5285