Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Maybe this will help? It's very, very basic and could be prone to errors.</p> <pre><code>$test = '&lt;ul&gt; &lt;li&gt; &lt;span&gt;&lt;span&gt;&lt;span&gt;Manager&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;/li&gt; &lt;li&gt; &lt;span&gt;&lt;span&gt;&lt;span&gt;physical&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;/li&gt; &lt;li&gt; &lt;span&gt;&lt;span&gt;&lt;span&gt;transport &lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;/li&gt; &lt;li&gt; &lt;span&gt; &lt;span&gt;&lt;span&gt; Australia&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;/li&gt; &lt;/ul&gt;'; echo preg_replace('/\n?&lt;(.*?)&gt;\n/', '&lt;$1&gt;', str_replace("\r\n", "\n", $test)); </code></pre> <p>Edit: I re-read your question and feel that wasn't exactly what you were after. So, I made this:</p> <pre><code>function strip_tag_nl($tag, $subject) { $tag = preg_quote($tag); return preg_replace_callback('/(&lt;' . $tag . '(.*?)&gt;)\n?(.*?)(&lt;\/' . $tag . '&gt;)/s', function($matches) { $stripped = preg_replace(array('/\n?&lt;(.*?)&gt;\n/'), '&lt;$1&gt;', $matches[3]); return $matches[1] . $stripped . $matches[4]; }, str_replace("\r\n", "\n", $subject)); } echo strip_tag_nl('li', $test); </code></pre> <p>Pass it the tag you want things between it to have newlines stripped. For example, <code>strip_tag_nl('ul', $text)</code> for your original question... if you do <code>strip_tag_nl('li', $text)</code>, you'll get this:</p> <pre><code>&lt;ul&gt; &lt;li&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;Manager&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;physical&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;transport&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt; Australia&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt; &lt;/ul&gt; </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. VO
      singulars
      1. This table or related slice is empty.
    2. 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