This has got me stumped, i have a form field where a user can enter PHP code which is then echoed back out. It works if just the code is entered, but if they include the opening and closing PHP tags i get: Parse error: syntax error, unexpected T_VARIABLE I don't want to strip the tags from the output, but rather ignore them from processing and echo them back out if they are included in the forms input. An example of what i'm doing i guess would be Pastebin.com, users enters PHP and it's echoed back out with formatting and line numbering. Any ideas, thanks.
Ok a description, a user pastes this in the form input: and it comes out: <?include("location.inc");?> PHP: With formatting, that's my desired result. But currently if the user pastes in the code with opening and closing PHP tags i get the error i mentioned above. If the user drops the opening/closing tags and just pastes the code it works fine. I want to be able to accept input with opening/closing PHP tags without throwing an error. Hope that's a bit clearer.
If the example is Pastebin, i guess this works. (notice the htmlentities() ) <?php // Read from form $user_code = $_POST['code']; // Echo it to user. echo 'Here is your code <br />', htmlentities($user_code); ?> PHP:
You would use htmlentities... <?php /* Get code e.g. url.com/file.php?code=<?php echo "hello world!"; ?> or you'd change the $_GET to $_POST if using a form. */ $code = htmlentities($_GET['code']); // echo the requested code echo "PHP Code:<br />".$code; ?> PHP: