TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Advanced PHP Programming (http://www.talkphp.com/advanced-php-programming/)
-   -   Having an issue with eval'd code (http://www.talkphp.com/advanced-php-programming/1752-having-issue-evald-code.html)

TlcAndres 12-17-2007 01:30 AM

Having an issue with eval'd code
 
Well this is the file thats being parsed

PHP Code:

<a href="<[siteurl]>"Hello </a>
<
phpcode>
if(
true)
{
    echo(
'ello there');
}
</
phpcode


and this is the file that runs the code within <phpcode>

PHP Code:

        //runs the php within template files             
        
public function Runphp($txt)
        {    
            
//split it away from the rest of the text
            
$php preg_split("/(<phpcode>.*<\\/phpcode>)/Us"$txt, -1PREG_SPLIT_DELIM_CAPTURE);
            
$stop count($php);
            
            
//run the loop and execute the php
            
for($phpe 0$phpe $stop; ++$phpe)
            {
                
$phpexc $php[$phpe];
                if (
preg_match("/^<phpcode>(.*)<\\/phpcode>/Us"$phpexc$phpexec))
                {
                    
$phpex_p $phpexec[1];
                    
ob_start();
                    eval(
$phpex_p);
                    
$c =  ob_get_clean;
                    
$c str_replace('ob_get_clean','',$c);
                    
$c preg_replace('/(<phpcode>.*<\\/phpcode>)/Us',$c,$txt,$stop);
                    return 
$c//return it
                
}
            }
        } 


maybe I'm missing something plainly obvious but the hello link is supposed to be before the 'ello there' and it's being switched around, any help would be appreciated


(sorry if it's in the wrong section)

ReSpawN 12-17-2007 04:03 PM

I kinda refixed the script, using PHP 5.2.5.
Execute.php;
PHP Code:

<a href="<[siteurl]>"Hello </a>
<
phpcode>
if(
true)
{
    echo 
'First off, why would you use echo ()? It\'s a function more simply used as echo "this";, not like you had.<br>';
    echo 
'next off, tryping if (TRUE) { on one line, not on two, will shorten the length of your script thus the load time.';
}
</
phpcode

File.php;
PHP Code:

<?php
        
        
//runs the php within template files             
        
function Runphp($txt)
        {    
            
//split it away from the rest of the text
            
$php preg_split("/(<phpcode>.*<\\/phpcode>)/Us"$txt, -1PREG_SPLIT_DELIM_CAPTURE);
            
$stop count($php);
            
            
//run the loop and execute the php
            
for($phpe 0$phpe $stop; ++$phpe)
            {
                
$phpexc $php[$phpe];
                if (
preg_match("/^<phpcode>(.*)<\\/phpcode>/Us"$phpexc$phpexec))
                {
                    
$phpex_p $phpexec[1];
                    
ob_start();
                    eval(
$phpex_p);
                    
$c =  ob_get_clean;
                    
$c str_replace('ob_get_clean','',$c);
                    
$c preg_replace('/(<phpcode>.*<\\/phpcode>)/Us',$c,$txt,$stop);
                    return 
$c//return it
                
}
            }
        }  

        
$file file_get_contents('execute.php');
        
        
Runphp($file);
        
?>

Exports:
PHP Code:

First offwhy would you use echo ()? It's a function more simply used as echo "this";, not like you had.
next off, tryping if (TRUE) { on one line, not on two, will shorten the length of your script thus the load time. 


Haris 12-17-2007 04:09 PM

Quote:

tryping if (TRUE) { on one line, not on two, will shorten the length of your script thus the load time.
I would never give up usability for 0.000000000000000001 ms of faster loading time.

Hence:

Quote:

Any fool can write code that a computer can understand. Good programmers write code that humans can understand.

ReSpawN 12-17-2007 04:35 PM

Quote:

Originally Posted by Haris (Post 6760)
I would never give up usability for 0.000000000000000001 ms of faster loading time.

Hence:

Hey, don't shoot the messenger. I simply read it somewhere and I picked it up. Next to that, why would you create one extra line at each if, else or elseif line? I guess the same goes for while, for and foreach? Your scriptsize will get smaller which is better.

Getting back to the real topic subject, let me know if it works out.

TlcAndres 12-17-2007 09:11 PM

the problem is not the running of the script it's how it presents the data

PHP Code:

<a href="<[siteurl]>"Hello </a>
<
phpcode>
if(
true)
{
    echo(
'ello there');
}
</
phpcode

it's supposed to be presented like so

PHP Code:

Hello ello there 

instead it's being presented as

PHP Code:

ello there Hello 



All times are GMT. The time now is 07:56 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0