There is the following trash in which you need to kill everything completely, even taking into account <![CDATA[ and get only the output - Text that needs to be received in its pure form

In short, clean everything before and after! I hope the essence is clear)

 <trash> Много разных символов, html и т.д. </trash> <![CDATA[ Текст который нужно получить в чистом виде. ]]> <trash> Много разных символов, html и т.д. </trash> 

    2 answers 2

     function getBetween($s1, $s2, $str){ $s = strpos($str, $s1) + strlen($s1); $e = strpos($str, $s2); return substr($str, $s, $e-$s); } $data = getBetween('<![CDATA[', ']]>', $text); 

    The problem is only if there are several such pieces. But then you can regExp'om.

    • There is no problem) there before <! [CDATA [and after]]> there is still a unique one on the page! Thank! - Palmervan

    $ pattern = "/ (<trash> [^>] +>) (s +) (<! [CDATA [) ([^ \ n] +) (s +]]>) s + (<trash> [^>] + >) / gm ";

    $ replacement = "$ 4";

    echo preg_replace ($ pattern, $ replacement, $ string);