Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>$html = &lt;&lt;&lt;HTML &lt;p&gt;Hello world&lt;/p&gt; HTML; // equivalent: $html = "&lt;p&gt;Hello world&lt;/p&gt;"; </code></pre> <p>This uses the <a href="http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc">PHP string Heredoc syntax</a>, which is a syntax to write a string, similar to using single quotes and double quotes but escape things in a somehow different way. You can use <code>{}</code> to directly insert some PHP strings into it.</p> <hr> <pre><code>&lt;?php ob_start(); ?&gt; &lt;p&gt;Hello world&lt;/p&gt; &lt;?php $html = ob_get_clean(); </code></pre> <p>This is a totally different thing. It makes use of the <a href="http://www.php.net/manual/en/book.outcontrol.php">PHP output buffering control</a> to capture things that are <em>not</em> inside PHP code blocks. Like in the given example, <code>&lt;p&gt;Hello world&lt;/p&gt;</code> is written outside the PHP code block, which is supposed to be output to the client immediately. With output buffering enabled they are stored inside a buffer in PHP, so that it can be retrieved later using <a href="http://www.php.net/manual/en/function.ob-get-contents.php"><code>ob_get_contents()</code></a> or <a href="http://www.php.net/manual/en/function.ob-get-clean.php"><code>ob_get_clean()</code></a>. If you need to insert any PHP variables, you need to use <code>&lt;?=$blah?&gt;</code> or even <code>&lt;?php echo $blah?&gt;</code>.</p> <hr> <p>Some CMS use the output buffering control functions to manage contents and modules. One example is Joomla. The advantage of this design is that whenever the module need to place content to its reserved space, it can simply use <code>echo</code> to make the content available. That can simplify the way to obtain contents from the modules, without needing to implement a specific function call or assign to a specific variable, which makes the system easier to manage.</p> <pre><code>&lt;?php ob_start(); include dirname(__FILE__)."/content.php"; $content = ob_get_clean(); output_document(array("body"=&gt;$content)); </code></pre> <hr> <p>I also make use of output buffering functions such that I can include one file on the top, and without having any PHP at the end I can create a simple template system, but this is sort of off-topic.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload