Web Analytics Made Easy -
StatCounter PHP parser - like the ones on here - CodingForum

Announcement

Collapse
No announcement yet.

PHP parser - like the ones on here

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

  • PHP parser - like the ones on here

    I am wondering how easy/hard it is to create a parser, where you can insert PHP into a textarea and on the output page it will colour PHP accordingly. Like the one on this forum. Is it a server installation? Downloadable code? Thanks
    Dave

  • #2
    PHP Code:
    <?php
    $str 
    '<?php echo "la de la"; ?>';
    $str highlight_string($str);
    echo 
    $str;
    ?>
    Give that a bash

    Comment


    • #3
      Thank you! Unless its real inconvenient, What about doing one where you can use [-P-H-P-]Without the hyphens[-/-P-H-P-]?

      Or will that do it
      Dave

      Comment


      • #4
        You'd need to use regex to do that, I'm not good at it but will see if this works for you
        Code:
        <?php
        
        $str = '[ php]<?php echo "la de la"; ?>[/ php]';
        
        $str = preg_replace("/^[php](.*?)[/\php]/$",highlight_string(\\1),$str);
        
        echo $str;
        
        ?>
        It might work, be lucky if it did lol

        Comment


        • #5
          OK, thanks alot, tbh it doesnt look like it will work but ill build from it
          Dave

          Comment


          • #6
            You wanna get mordred's attention to here, he's like the a-team of regex.

            Comment


            • #7
              im not great myself, but try:
              PHP Code:
              <?php

              $str 
              '[[b][/b]php]<?php echo "la de la"; ?>[/[b][/b]php]';

              $str preg_replace("/\\[php\\](.*)[\\/php\\]/ise"highlight_string("$1"), $str);

              echo 
              $str;

              ?>
              PHP Weekly - A PHP Developers Resource
              PHP 5.1.4 and Ruby on Rails web hosting
              Moderator of PHP and Work offers and Requests
              Install Apache/PHP/MySQL
              (by marek_mar) | TinyPlugin Architecture

              Comment


              • #8
                again, thanks ill take a look
                Dave

                Comment

                Working...
                X