Page 1 of 1

Using php In Arrays

Posted: Sat Jan 08, 2005 6:27 am
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]

Posted: Sat Jan 08, 2005 8:52 am
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.