Jenna Maiz Jenna Maiz - 1 year ago 48
HTML Question

How to clean up HTML/XML?

I am getting a web service response as follows:

<text>&lt;span class="TitleServiceChange" &gt;Service Change&lt;/span&gt;
&lt;span class="DateStyle"&gt;
&amp;nbsp;Posted:&amp;nbsp;10/19/2016&amp;nbsp; 8:04PM
&lt;P&gt;&lt;STRONG&gt;B103-Ltd&lt;/STRONG&gt; and &lt;STRONG&gt;BM2 &lt;/STRONG&gt;buses are detoured due to paving on Avenue M between Remsen Av and E. 95 St. &lt;/P&gt;
&lt;P&gt;Detour is as follows: &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Eastboun&lt;/STRONG&gt;d: Via Avenue M. right on Remsen Av, left on Avenue N, left on Rockaway Pkwy, right on Avenue M and regular route. &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Westbound&lt;/STRONG&gt;: Via Avenue M, left on E. 95 St, right on Avenue N, right on E. 85 St, right on Remsen Av, left on Avenue M, and regular route. &lt;/P&gt;
&lt;P&gt;All corresponding stops will be made along the detoured route. &lt;/P&gt;
&lt;P&gt;Allow additional travel time. &lt;/P&gt;

I am not particularly sure what this notation is but it seems like the <> of HTML tags have been converted &lt and &gt(less than and greater than) with other HTML. Is there a way to clean up this response, so I can just have the plain text ?

Answer Source

First use htmlspecialchars_decode to convert special character to HTML tags and then use the resulted string in the strip_tags to remove html tags. After it you will have only text.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download