开发者

advice on php parsing

开发者 https://www.devze.com 2022-12-09 15:24 出处:网络
I am using phpTumblr, a wrapper around the tumblr blog api that allows you to access posts via php. I want the site to display new posts dynamically, so I am using php to write html code. I find mys

I am using phpTumblr, a wrapper around the tumblr blog api that allows you to access posts via php.

I want the site to display new posts dynamically, so I am using php to write html code. I find myself writing things like print(blablabla); or print(); ... and so on, and setting the header of the document to text/html, so that the browser would read it as html.

This just seems to me like a kind of ugly hack, and I was wondering if most dynamic pages are set up in this way, or are t开发者_如何学Gohere different ways to convert php objects(say arrays) automatically into html tags. So far it doesnt seem like there are any.) maybe i have to be using some CMS software?

Any advice would be great.

Thanks


I believe what you're describing is known as a template engine. It essentially separates the logic from the UI, and allows you to write dynamic pages without an excessive number of print or echo statements.

For PHP, I would recommend Smarty, but Google can also help you with finding alternative ones if you find you don't like it.


PHP is a language in which you can do alot of different things and one of them is to send output to browsers. So if you want to print an array as HTML code , write a PHP function for it. PHP has NOTHING to do with HTML tags directly.

Like the above post mentions you can use Smarty templating engine ... BUT then you will need to learn the smarty language to print the array :)

All scripting languages work in this way. So lets say if any xyz language supports a function called print_array_as_html($array) .... then observe that it is a function. That's the idea of having functions/methods in a language , extend the functionality to get what you need.

0

精彩评论

暂无评论...
验证码 换一张
取 消