highlight_string()

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    highlight_string()

    ok i know i started my own syntax highlighting project before. but i wanted to try and use the built in php syntax highlighter
    for experimental purposes.

    any ideas why isnt this working.

    PHP Code:
     /** Show Post */
    function Show_Post($Posts_To_Show$File_Path)
    {
    $Show_Posts file($File_Path);
    for(
    $k 0$k<$Posts_To_Show$k++)
    {
    echo 
    preg_replace('/<div class="codebox">(.*?)<\/div>/i''<div class="codebox">'.highlight_string('\\1'true).'</div>'$Show_Posts[$k]);
    }
    /** End Of Show Post Function */
    //
    //

    // 
    its an attempt to use php built in highlighter.

    but the resulting source code come back like this when displayed..

    PHP Code:
    <div class="codebox"><code><span style="color: #000000">
     
    /** Show Post */
    function Show_Post($Posts_To_Show$File_Path)
    {
    $Show_Posts file($File_Path);
    for(
    $k 0$k<$Posts_To_Show$k++)
    {
    echo 
    preg_replace('/<div class="codebox">(.*?)<\/div>/i''<div class="codebox">'.highlight_string('\\1'true).'</div>'$Show_Posts[$k]);
    }
    /** End Of Show Post Function */
    </span></code></div>
    //

    //
    //
    // 
    basically just turning all text black.
    so its finding the string of code. adding the code tag and only 1 span style color.

    i was wondering if it would possibly have something to do with the htmlentities i set on the string before adding it to database.
    then use this function to pull the string from the database then try to highlight it.
    <?php
    include ('Ghost');
    if ($Post == true) {
    echo '

    sigpic
    alt='coding-talk.com!!' />';
    echo 'Sharing Is Caring!';
    } else {
    echo '

    alt='the username GHOST has been comprimised!' />';
    echo 'OMG SOMEBODY HELP ME!!';
    }
    ?>

    #2
    Yes, highlight_string() is doing html chars conversion it self.
    <!DOCTYPE html PUBLIC "-//WAPFORUM.RS

    Comment


      #3
      i was hoping that wouldnt be the case.

      as i need htmlentities() to be used so i dont have raw php code going into the database.
      or else if would make the text outside the codeboxes to become vunerable to attacks.

      ive tried many things. including trying to html_entity_decode() just the text inside the codebox but it still returns black text rather than colored.

      PHP Code:
      echo preg_replace('/<div class="codebox">(.*?)<\/div>/is', '<div class="codebox">'.highlight_string('<?php echo "$test"?>', true).'</div>', $Show_Posts[$k]);
      //
      //
      //
      works perfectly. so i know its an issue with the \\1 or $1 regexing (ie: the grabbed code inside the box)

      so i tried it with wrapping it in php tags too like so.

      PHP Code:
      echo preg_replace('/<div class="codebox">(.*?)<\/div>/is', '<div class="codebox">'.highlight_string('<?php '.'\\1'.' ?>', true).'</div>', $Show_Posts[$k]);
      //
      //
      //
      but then that just sent back <?php \1 ?> rather than the text. although this time it was colored.

      its just frustrating. this is suppose to be the easy route. rather than making your own.
      but ive had more issues trying to correct this than i had making my own upto the point where i had
      that commenting issue lol.
      <?php
      include ('Ghost');
      if ($Post == true) {
      echo '

      sigpic
      alt='coding-talk.com!!' />';
      echo 'Sharing Is Caring!';
      } else {
      echo '

      alt='the username GHOST has been comprimised!' />';
      echo 'OMG SOMEBODY HELP ME!!';
      }
      ?>

      Comment


        #4
        it sounds like you have another code that you have not showed us interfering with the code....
        im guessing you could do a string replacement for the code and replace // with ///

        Comment

        Working...
        X