SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard mark_W's Avatar
    Join Date
    Mar 2004
    Location
    West Midlands, United Kingdom
    Posts
    2,631
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Submit php code form

    Hiya,

    I have created a form for submitting php code.

    What i want is, you type in the code and then it echos it back with syntax highlighting.

    At the moment i have this

    PHP Code:

    <?php
    if (isset($submit)) {
        
    $phpcode $_POST['phpcode'];
        echo 
    preg_replace(
            
    "'\[php\](.*?)\[/php\]'msie",
            
    "highlight_string('$1',true)",
            
    $phpcode
          
    );
    } else {
    ?>
    <html>
    <body>
    <form action="" method="POST">
    <textarea cols="50" rows="20" name="phpcode"></textarea>
    <input type="submit" name="submit" value="Add Code">
    </form>
    </body>
    </html>
    <?php
    }
    ?>
    If I add this code into the form

    PHP Code:
       
    <?php

    //little bit of testing

    $testing "just testing";

    echo 
    $testing;

    ?>
    It displays everything with highlighting but gets an error as below

    PHP Code:

    <?php

    //little bit of testing

    $testing =
    WarningUnexpected character in input'\' (ASCII=92) state=1 in /home/protemp/public_html/highlighter.php(9) : regexp code on line 11

    Warning: Unexpected character in input: '
    \' (ASCII=92) state=1 in /home/protemp/public_html/highlighter.php(9) : regexp code on line 11
    "just testing\\";

    echo $testing;

    ?>
    Any help appreciated

    Mark.

  2. #2
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Örebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Try to enclose your pattern in a different character than an apostrophe.
    Does it make any difference if you use for example ~ instead of '?

    Yours, Erik.

  3. #3
    SitePoint Wizard mark_W's Avatar
    Join Date
    Mar 2004
    Location
    West Midlands, United Kingdom
    Posts
    2,631
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Erik,

    Im not entirley sure what you mean, I tried changing to:

    PHP Code:
      
      
    "'\[php\](.*?)\[/php\]'msie" 
    is that what you mean, if so, it never worked!

  4. #4
    SitePoint Wizard mark_W's Avatar
    Join Date
    Mar 2004
    Location
    West Midlands, United Kingdom
    Posts
    2,631
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I still cant get this working!

    Any ideas anyone!?

  5. #5
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Örebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I ment that you should try using a different character to enclose your pattern, like this:
    PHP Code:
    "~\[php\](.*?)\[/php\]~msie" 
    Yours, Erik.

  6. #6
    SitePoint Wizard mark_W's Avatar
    Join Date
    Mar 2004
    Location
    West Midlands, United Kingdom
    Posts
    2,631
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi again Erik,

    i figured you mean that and tried it but it was still no good!

    thanks


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •