File_get_contents kullanarak bir dizeye yerel bir PHP dosyasından HTML çıkış saklanması

4 Cevap php

There is a header.php file and it contains some php codes that return HTML. I know I can use require, include to echo the results, but what I want to do is to store its processed output string into a variable.

Bir sayfada, ben kullanılan:

$headerHTML=file_get_contents('header.php');

Then I got the PHP code output rather than the processed HTML output. I know adding http:// would help. But I prefer to keep using relative path, how can I tell the function to treat the php file correctly?

Not: Ben oldukça ob_start() mümkünse kullanmaktan daha bu ifadeyi file_get_contents kullanmaya devam etmek istiyorum.

4 Cevap

Ben oldukça require() ob_start() içine sarılmış ve ob_get_clean() kullanmak istiyorum. Ben bu yaklaşımı ile yanlış bir şey yoktur eminim.

Kullanmayınız eval() - o kötülük!

Göreceli yerel yol, bir automatically map it to a absolute URL kullanın.

URL sarmalayıcıları etkin ve header.php çıkışını istiyorum (ve oturum durumunu tutmak istemiyorum) neden böyle bir şey beni kendimden geçiriyor yapmak istersiniz olsa, $headerHTML=file_get_contents('http://yourdomain.tld/path/to/header.php'); kullanabilirsiniz eğer. Eğer kolayca şablonlar ve önbelleğe kullanılarak çözülebilir bir şeyler yapmaya çalışıyor, değil mi emin misin?

Sen http://in2.php.net/manual/en/function.eval.php#56641, yardımcı olur umarım kontrol edebilirsiniz.