PHP don't parse PHP code from sql result

Soldato
Joined
24 May 2006
Posts
3,828
Location
Surrey - UK
Quick question for anyone in the know who might be able to help.

I'm modding a plugin for Wordpress, and i'm grabbing various fields from the database.

I want to use 1 field to actually store PHP code that i'd like to print out onto the page...

Problem, the code keeps getting parsed or removed, although the data remains in tact...

I've tried code and pre of course, but it's still removing any..
Code:
<?php ?>
and whatever is inside when displaying on the page...

Any ideas fellas?
 
Soldato
Joined
18 Oct 2002
Posts
5,464
Location
London Town
You need to encode the code block when outputting in the page so PHP doesn't interpret it as PHP code, and the browser doesn't interpret it as HTML code (it'll consider <?php as the start of an HTML tag).

So,

Code:
$phpcode = '<?php echo 'hello world'; ?>';
echo htmlspecialchars($phpcode);
 
Soldato
OP
Joined
24 May 2006
Posts
3,828
Location
Surrey - UK
It's ok, i'm just coming back to say i've fixed it....

It's actually a plugin i downloaded for modding purpose. It was intended to display code, so i had to hack it a little. Basically i'm converting a plugin into a code snippet area...

Just needed to use htmlenetities and stripslashes in the end.

I'll post a link once it's up so you have a better idea of what i'm doing. The whole point was to avoid writing a plugin for some very basic, so i went about hunting for the closest thing, then started hacking it up and removing the bits i don't need.

It started off as an address book plugin.... it's going to be something totally different by the time i'm finished.... :) albeit less impressive because i only actually need a few bits from it... :)

Thanx for the suggestion anyway Jim...
 
Back
Top Bottom