Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Consider using the HEREDOC syntax. <a href="http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc" rel="nofollow">http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc</a></p> <pre><code>&lt;?php $my_string = &lt;&lt;&lt;EOD &lt;script type="text/javascript"&gt; var x = "this string has a ' known as a single quote!"; &lt;/script&gt; EOD; ?&gt; </code></pre> <p>The advantage with this syntax is being able to freely write your html or javascript without escaping quotes.</p> <p><strong>Update</strong></p> <p>Here is a little more info on HEREDOC.</p> <p>First and foremost the most common error related to heredoc syntax is caused by whitespace. HEREDOC syntax requires an opening and closing identifier. In the example above I have used <code>EOD</code> as the identifier. It is important that the opening identifier has no whitespace after it and the closing identifier is on a new line, has no whitespace before it and no whitespace between the identifier and the semi-colon.</p> <p>You do not have to use <code>EOD</code> as your identifier. You can use something more descriptive. I like to use an identifier that describes the block of code.</p> <pre><code>&lt;?php $html = &lt;&lt;&lt;HTML &lt;html&gt; &lt;head&gt; &lt;title&gt;Example html&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;p class="paragraph"&gt;This is my html!&lt;/p&gt; &lt;/body&gt; &lt;/html&gt; HTML; $javascript = &lt;&lt;&lt;JAVASCRIPT &lt;script type="text/javascript"&gt; var helloText = "Hello, my name is Jrod"; alert(helloText); &lt;/script&gt; JAVASCRIPT; ?&gt; </code></pre> <p>To use variables inside your heredoc syntax you will need to use curly braces around your variable in the code.</p> <pre><code>$widget = &lt;&lt;&lt;WIDGET &lt;p&gt;Good Morning {$name}&lt;/p&gt; WIDGET; </code></pre>
    singulars
    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.
    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