Aris
Aris

Reputation: 5057

echo html variable, that includes a php include

I have this issue. I have HTML code stored in the database. I read it, and I display it in my pages using echo $page_content;

I want to add somewhere in the middle of this HTML code a php include. Something like this: Inside this file I have also html code which is basically the country options for a select:

<option selected="selected" value="">Choose...</option>
<option value="AFGHANISTAN">AFGHANISTAN</option>
<option value="ALBANIA">ALBANIA</option>
<option value="ALGERIA">ALGERIA</option>
<option value="AMERICAN SAMOA">AMERICAN SAMOA</option>
<option value="ANDORRA">ANDORRA</option>
<option value="ANGOLA">ANGOLA</option>
etc etc

Until now I have hard-coded all the countries in many places, which I don't like.

But this is not displayed at all when i do my echo $page_content;

Upvotes: 0

Views: 290

Answers (2)

zaf
zaf

Reputation: 23244

One of the easiest ways is to use tokens that get replaced with the content.

This can avoid the use of eval - which is not recommended ane would get me down voted by the herd.

For example:

HTML CODE

Hello, _TOKEN2_!

You can then use string replace functions to replace the TOKEN2 (the underscores are there but seemed to disappear here) with whatever you want:

str_replace("_TOKEN2_","World",$page_content);

And so on, you get the idea.

Upvotes: 2

Brian
Brian

Reputation: 8616

I would recommend you look into using something like Smarty to separate you're PHP and layout.

Upvotes: -1

Related Questions