problem with replace

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
AndrewBacca
Forum Commoner
Posts: 62
Joined: Thu Jan 30, 2003 10:03 am
Location: Isle of Wight, UK

problem with replace

Post by AndrewBacca »

Code: Select all

$template = str_replace("<% main %>", $main, $template);
$main is data from a .php file which contains the following

Code: Select all

<? print "blah"; ?>
but when i go to my browser and run it all, it replaces it all ok, but the above php doesn't "compile" I check the source code (in firefox) and it looks like this

<? print "blah"; ?>

anyone got any ideas as this is annoying the hell out of me!
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

eval() :)

But do becareful when using eval!
User avatar
AndrewBacca
Forum Commoner
Posts: 62
Joined: Thu Jan 30, 2003 10:03 am
Location: Isle of Wight, UK

Post by AndrewBacca »

thnx!

what do I do if the template string has none php code in it tho?
User avatar
AndrewBacca
Forum Commoner
Posts: 62
Joined: Thu Jan 30, 2003 10:03 am
Location: Isle of Wight, UK

Post by AndrewBacca »

>> Resolved :)
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post by BDKR »

I know this is resolved, but I just wanted to reinforce the warning from Jenk. If you are running code that is stored in a database, you need to be extra careful and dilligent in your policy about exactly what coming out of a db is eval'd, and even more important, strict policies about what goes in and how it get's in there.

Isle of Wight eh? I'd like to visit that place someday.

Cheers
Post Reply