Using php In Arrays

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
ek5932
Forum Commoner
Posts: 25
Joined: Mon Jun 28, 2004 5:55 pm

Using php In Arrays

Post by ek5932 »

feyd | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


On my website I am using an array to replace text into html

Code: Select all

function addcode($input){
$search = array('[general_nav]','[admin_nav]','[welcome]'); 
$replace = array(
"<b>Navigation:</b><br>
<A href=>Home Page</A><br>
<A href=>Private Forums</A><br>
<A href=>Polls</A><br>
<A href=>News Articles</A><br>",
"<b>Admin:</b><br>
<A href=>General Settings</A><br>
<A href=>Website Colors</A><br>
<A href=admin/headers.php>Headers & footers</A><br>
<A href=>Manage Pages</A><br>
<A href=>Manage Forums</A><br>",
"Welcome, <b>killa</b>:<br>
<a href=>Account Setpup</a><br>
<a href=>Logout</a>"
);

$input = str_replace($search, $replace, $input);
return $input;}
But can i replace the code with PHP? All the actual code of the website is stored in my DB and I plan to echo the code and replace things like [date] with <?echo$date;?> but it just comes out as a blank space.

Any help would be great, thanks!


feyd | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

yes, you can.. but in order to run php code that's stored in a string, it has to be eval'd... which is rarely recommended, because of dangers of manipulation. It's often simple enough to preprocess values for output like the date.

Also note that you will need to make sure the $date doesn't get parsed as a variable.
Post Reply