Jump to content

[SOLVED] Load the HTML output of a file into a variable?


AbydosGater

Recommended Posts

Hi, Simple question. But i cant figure it out.. How can i load the html output of a file into a variable.. Kind of like include()ing or require()ing a file.. but not echoing the content.. but saving it to a variable..

 

Can it be done? I dont want to use fgets because they are PHP files.. and i want to get the HTML as if a user opened with a browser..

 

 

Andy

Link to comment
Share on other sites

Just a thought.  You may want to try php's strip_tags function.  You could assign the whole document as a variable then strip the html in another variable and then use str_replace to delete the strip_tags variable (which is all content other than html) out of the original variable leaving html left.  

Link to comment
Share on other sites

Barrand: Ahh, Thats more understandable then what i have seen before.

Will get right on it.

 

Thank You

 

DanFavourite: I dont need to strip the html.. Its for my template class i need to keep the HTML.

 

Ill try using OB.. That or Eval.

Link to comment
Share on other sites

Try this:

 

<pre><?php

$page = html_entity_decode(strip_tags(file_get_contents("http://yoururl/file")));

echo $page
?></pre>

 

I'm not sure which is more appropriate, html_entity_decode() or htmlspecialchars_decode().  I think html_entity_decode() is more thorough.

Link to comment
Share on other sites

Im Not Trying to take out the HTML! I need the html and want the html. Its the PHP i dont want..

 

When you include a file into your application.. It runs it first, as if you opened said file in your browser.. and it returns the HTML for the browser to display..

 

I want to do this! But not display the code for the page.. But save it to a variable.

 

Unfortunately all methods i have tried..fgets().. file() and get_file_contents() have all returned the actuall PHP code for the page... before its been processed..

 

I need it after its been processed.. with all html tags..

 

But i cant find a way to do it

 

EDIT: Does eval(); echo or output the result after it has been called.. or can the result be saved to a variable to be outputted later?

Link to comment
Share on other sites

To answer my last question.. I tried

<?php
$str = 'if (1 == 1) {echo "true";};';
$var = eval($str);
echo $var;
?>

 

And no it cant save the returned result to a variable it just outputs the result on being eval'd.

 

Does anyone know how i could get around this problem?

Please

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.