Ok this is it in a nutshell.
I'm using a nice bit of script doing this.
$base = explode("|", $file[$arr]);
But now the thing is... I'd like to check if a certain bit resulting from this is script... say $base[2] .. is script or text
And I'd like to run this bit as php script in stead of just printing it in a nice table.
So I got to check if the first 5 characters of $base[2] are <?php and if so.. then run it... I haven't been able to figure it out yet.
Or is it possible to just enter a code in the middle of any textbit that you retrieve from file that will be run? Or have a bit of script do that for you?
running script from textfile array
Moderator: General Moderators
-
samscripts
- Forum Commoner
- Posts: 57
- Joined: Tue Apr 23, 2002 4:34 pm
- Location: London, UK
Hi, the function you need to use is eval().
Example:
It will execute the string passed to it as php code. Notice though that you shouldn't have the <?php...?> tags at the beginning and end of the code to be eval'd, although it is ok to jump in and out of php withing the eval'd stuff.
ie: This will not work:
but this will:
Hope this helps you out 
Example:
Code: Select all
<?php
$base = array("Hello", "<br>", "<?php echo 'world';?>", "<br>","is this what you wanted?");
for( $i = 0; $i < count($base); $i++){
if( substr($baseї$i], 0, 5) == '<?php'){
$code = substr($baseї$i], 5, strlen($baseї$i])-7);
eval( $code);
}else{
echo $baseї$i];
}
}
?>ie: This will not work:
Code: Select all
$code = "<?php echo 'hello world';?>";
eval ( $code);Code: Select all
$code = "echo 'hello world';?><hr><b><?php echo 'Understand?';?>";
eval ($code);