Note that there are some explanatory texts on larger screens.

plurals
  1. POregex - preg_split getting inline script tags
    primarykey
    data
    text
    <p>I'm trying to separate individual inline script tags:</p> <pre><code>&lt;script&gt; console.log('hello'); console.log('hi!'); console.log('yo!'); &lt;/script&gt; &lt;script type="text/javascript"&gt; console.log("this is another inline script"); var hi = "cool"; console.log(hi); &lt;/script&gt; </code></pre> <p>Here's the pattern that I'm using:</p> <pre><code>$scripts = preg_split('#(&lt;script&gt;.*?&lt;/script&gt;|&lt;script type="text/javascript&gt;.*?&lt;/script&gt;")#', $str); </code></pre> <p>But I'm getting this result:</p> <pre><code>Array ( [0] =&gt; &lt;script&gt; console.log('hello'); console.log('hi!'); console.log('yo!'); &lt;/script&gt; &lt;script type="text/javascript"&gt; console.log("this is another inline script"); var hi = "cool"; console.log(hi); &lt;/script&gt; ) </code></pre> <p>While I'm expecting to get something like this:</p> <pre><code>Array ( [0] =&gt; &lt;script&gt; console.log('hello'); console.log('hi!'); console.log('yo!'); &lt;/script&gt; [1] =&gt; &lt;script type="text/javascript"&gt; console.log("this is another inline script"); var hi = "cool"; console.log(hi); &lt;/script&gt; ) </code></pre> <p>What's wrong with the pattern that I'm using? Thanks in advance!</p> <p><strong>Update</strong></p> <p>If I use the <code>s</code> modifier I get something like this:</p> <pre><code>Array ( [0] =&gt; [1] =&gt; &lt;script type="text/javascript"&gt; console.log("this is another inline script"); var hi = "cool"; console.log(hi); &lt;/script&gt; ) </code></pre> <p>It manages to separate the 2 scripts but the first script becomes an empty string</p>
    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.
 

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