Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Apr 2005
    Location
    Burnaby, BC, Canada
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Executing PHP from MYSQL DB Problem

    Hi guys.

    I have a variable that contains this:

    <P>
    [php-]
    print "HELLO THERE";
    [/php-]
    </P>

    [script-]
    alert ("HI!");
    [/script-]

    Right now I have it being turned into this:

    print "<P>";
    print \"HELLO THERE\";
    print " </P>
    <script language=\"javascript\">
    alert (\"HI!\"); </script>";

    What I need is for the quotations between the original [php-] and [/php-] to not be escaped. I used addslashes to escape the variable in the first place to fix the quotes outside of the php tags.

    I am using this so I can store php code inside of pages, that will be executed using exec when the page is being displayed.

    If anyone could tell me how to fix this, or has an alternate way of doing this, please let me know.

    Thanks a lot.
    'Programming is the only artform that fights back!'

  • #2
    Regular Coder devinemke's Avatar
    Join Date
    Dec 2004
    Location
    NYC
    Posts
    443
    Thanks
    0
    Thanked 12 Times in 11 Posts
    just store the code as a string and use the eval fucntion.

  • #3
    New Coder
    Join Date
    Apr 2005
    Location
    Burnaby, BC, Canada
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thats what I'm doing, but I have html and PHP code stored in the the database together in 1 record.

    I need the non php code to have escaped quotations, and the php code to not be escaped.

    Thats what my problem is.
    Last edited by diablo2_v; 07-04-2005 at 01:54 AM.
    'Programming is the only artform that fights back!'

  • #4
    New Coder
    Join Date
    Apr 2005
    Location
    Burnaby, BC, Canada
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, I got around my problem. Its not the best way, but it will do. If anybody can improve upon it, go ahead.

    PHP Code:
    while ($start strpos($cont"[php-]"$end))
    {
        
    $end strpos($cont"[/php-]");
        
        if (
    $end === false)
            
    $end strlen($cont);

        
    $temp substr($cont$start$end);
        
    $temp2 stripslashes($temp);
            
        
    $cont str_replace($temp$temp2$cont);
        print 
    htmlentities($temp2) . "<br /><br />";

    It just searches for a [php-] tag, and if it finds one, then searchs for a [/php-] tag. Then it strips the slashes from that section of the string, and switches the updated version of the string with the old version.
    'Programming is the only artform that fights back!'


  •  

    Posting Permissions

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