Raphael Jeger
Raphael Jeger

Reputation: 5232

Why are my paths absolute after ob_get_contents in PHP?

For saving the executed contents of a php-File in a variable, I do the following:

ob_start();
include '/templates/post.php';
$html = ob_get_contents();
ob_end_clean();
return $html;

which works nice.

However, in the included "post.php", I have relative links to ressources like images. Why on earth are they absolute, full qualified links on my localhost and also on the server? Locally, they look like:

http://localhost/myProjectname/img/img1.png

which is weird because in post.php, there's written:

<img src="/img/img1.png">

which is also an absolute, but not full qualified path to the file and I can't find any other reason apart from ob_get_contents. Am I missing something? Thanks!

Upvotes: 0

Views: 205

Answers (0)

Related Questions