I don't know if the title of my question is properly described.
I'm working on a project that uses some PHP + HTML-formatted code, and then I need to save all of the output HTML results to a cache.
My only solution now is to write the php+html format code that I want to save as a similar
$cache = "html". php. " HTML ";
The $cache variable can then be cached.
Is there a way for me to put these PHP + HTML code in a file, and then read the effects of their output into a variable?
For example I have such a few code
'" onmouseout="this.style.cssText='background: #333;'"> ID,'post_describe',true);if(!$post_describe){echo strimwidth(strip_tags(apply_filters('the_content', $post->post_content)), 0, 142, '');}else{echo $post_describe;}?>
There are some statements like if in the code, I'm not convenient. They all write in one line and then throw a variable inside. This is not conducive to late revision.
So I'm looking for other better ways.
I found that using include directly outputs the contents of the file without returning the content to a variable.
Reply content:
I don't know if the title of my question is properly described.
I'm working on a project that uses some PHP + HTML-formatted code, and then I need to save all of the output HTML results to a cache.
My only solution now is to write the php+html format code that I want to save as a similar
$cache = "html". php. " HTML ";
The $cache variable can then be cached.
Is there a way for me to put these PHP + HTML code in a file, and then read the effects of their output into a variable?
For example I have such a few code
'" onmouseout="this.style.cssText='background: #333;'"> ID,'post_describe',true);if(!$post_describe){echo strimwidth(strip_tags(apply_filters('the_content', $post->post_content)), 0, 142, '');}else{echo $post_describe;}?>
There are some statements like if in the code, I'm not convenient. They all write in one line and then throw a variable inside. This is not conducive to late revision.
So I'm looking for other better ways.
I found that using include directly outputs the contents of the file without returning the content to a variable.
That's a good question. In fact, this is the direct use of PHP as a template language.
Http://php.net/manual/en/function.includ ...
Look at the Example here #6 Using output buffering to include a PHP file into a string
Content that is not bound by PHP code is output to a response, and you cannot block it, but you can only use the Redirect method to capture it.
Resolved, adding in the middle of the include
ob_start(); 你的代码$html = ob_get_contents();ob_end_clean();
Ob_start can then put the output in the buffer, rather than directly back to the user, and then through Ob_get_contents get to