[PHP] Remove PHP... From PHP

NSA

sudo apt-get thefuckout.tar.gz
Dec 9, 2011
715
86
Okay, so this seems like a stupid question first, but don't get off-tracked.

I'm creating a system that allows users to create... plugins of a sort.
However, I'd like to let them use HTML etc... but not PHP.
Is there anyway I can remove PHP from an included file?
I'm using output buffering at the minute to put the include into a variable and have tried numerous preg_replace's.

Any help would be appreciated.
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,638
2,393
On iPad currently taking a shit right now so not sure if this'll work but whatever

PHP:
<?php
$file_with_php = @file_get_contents('somefile.php');
if (preg_match('/^\<\?/', $file_with_php) && preg_match('/\?\>$/', $file_with_php)) {
    //file has php
} else {
    //no php
}
?>
 

NSA

sudo apt-get thefuckout.tar.gz
Dec 9, 2011
715
86
That scripts seems to work when $file_with_php has a pre-defined value i.e. $file_with_php = "<?php echo 'hi'; ?>"; but not when including or using file_get_contents.
 

NSA

sudo apt-get thefuckout.tar.gz
Dec 9, 2011
715
86
I've found there's no problems with including the file, however, the PHP is actually commented out.
I'd rather have it removed than being commented out.
If the PHP contained database information... you already know the rest.
 

Users who are viewing this thread

Top