PHP Strip HTML Tags

nainil
nainil used Ask the Experts™
on
I have an rss feed and I want to strip html and special characters except the following from the same:

" . , ; & - ! @ # $ % * ( ) {} [ ] < > / \ |

I know php's strip tags does partial html stripping but not tags like <img etc.

Any help would be appreciated.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Erdinç Güngör ÇorbacıPHP Development Team Leader

Commented:
try a function like this  (You can recode some parts if you need to customize )
but for instance how do you wish to remove tags of

<a href="javascript:onmouseover('myhover');">text0  text1 text2 </a>

?
Most Valuable Expert 2011
Top Expert 2016

Commented:
You do not want to strip the tags.  You want to "entitize" the tags.  Choose one of these functions to help you get the data right.
http://php.net/manual/en/function.htmlspecialchars.php
http://php.net/manual/en/function.htmlentities.php

RSS is XML and XML cannot have certain characters in clear text, except as part of the XML data transport mechanism.  The wickets < and > are among these.

If you want to show us some of the RSS feed that you're working with I expect we can show you how to process it correctly.

Author

Commented:
Here are some examples:
<div readability="137.61176152738">
<p><span class="image rtsm"><img src="http://zapp5.staticworld.net/images/article/2011/05/google_facebook_logos180-5173572.jpg" alt="" height="119" width="180"/></span>This just in: Facebook and Google <a href="http://www.pcworld.com/article/227903/facebooks_antigoogle_efforts_get_muddier.html?tk=rel_news" target="_blank">don't like each other</a> much. How do we know this? Because Facebook hired a very expensive PR firm to <a href="http://www.itworld.com/internet/164619/blogger-blows-lid-secret-facebook-scheme-smear-google" target="_blank">plant negative stories about Google</a> in the press.</p>
<p>In case you missed this story, here's the Readers Digest version: Facebook hired PR mavens-to-the-stars Burson-Marsteller to paint Google Social Circles <a href="http://pastebin.com/zaeTeJeJ" target="_blank">as the most evil thing</a> to happen since Fox Networks cancelled "Firefly." From Burson-Marsteller's email pitch:</p>
<blockquote readability="9">&#13;
<p><em>Google is collecting, storing and mining millions of people's personal information from a number of different online services and sharing it without the knowledge, consent or control of the people involved.</em></p>&#13;
</blockquote>
<p>The problem: Facebook did this in the <a href="http://www.infoworld.com/t/cringely/facebooks-failed-google-smear-stupidity-squared-979" target="_blank">stupidest way possible</a>, and tried to do it in secret. Didn't work. Oops.</p>
<p><strong>[ See also:</strong> <a href="http://www.itworld.com/security/164069/would-you-trust-hbgary-i-don-t" target="_blank"><strong>Would you trust HBGary? I don't.</strong></a> <strong>]</strong></p>
<p>Got this official comment from a Facebook spokeshuman yesterday:</p>
<blockquote readability="15.34833869239">&#13;
<p><em>No 'smear' campaign was authorized or intended. Instead, we wanted third parties to verify that people did not approve of the collection and use of information from their accounts on Facebook and other services for inclusion in Google Social Circles -- just as Facebook did not approve of use or collection for this purpose. We engaged Burson-Marsteller to focus attention on this issue, using publicly available information that could be independently verified by any media organization or analyst. The issues are serious and we should have presented them in a serious and transparent way.</em></p>&#13;
<p><em>You and your readers can look at the feature and decide if they have approved of this collection and use of information by clicking here when their Google account is open:</em> <a href="http://www.google.com/s2/search/social"><em>http://www.google.com/s2/search/social</em></a><em>. Of course, people who do not have Gmail accounts are still included in this collection but they have no way to view or control it.</em></p>&#13;
</blockquote>
<p>OK, maybe Facebook had a point. I decided to check it out.</p>
<p>I clicked the link, which brought me to a Google Social Search page. This told me I had 31 direct connections via Google Chat, another 990 via Google Profiles or Connected accounts, and some 2,858 "secondary connections." These would be people I don't necessarily know but who are connected to the people I do know.</p>
<p>Presumably, this would be where the privacy violations that so vexed Facebook would appear. After all, many of them are complete strangers to me; why should I know anything about them?</p>
<p>Only one problem: I couldn't find any vexing privacy violations. Take a look at what my Google Search Profile looks like:</p>
<p><span class="image large"><img src="http://www.itworld.com/sites/default/files/images/google%20social%20search%20-%20dan%20tynan%20paths.jpg" alt="google social search results" height="207" width="589"/><span class="artCaption">google social search results</span></span><strong>google social search results</strong></p>
<p>Shocking, ain't it? This is about as detailed as <a href="http://www.pcworld.com/article/222012/google_circles_looms_but_do_googles_nerds_get_social.html?tk=rel_news" target="_blank">Google Social Circles</a> gets, and it's only this detailed because I voluntarily added all these links to my public Google Profile. There's nothing in there that isn't already public information, available to anyone with enough gray matter to type a query into a search engine.</p>
<p>Now for some stats: Twitter accounted for 4,192 of my social search connections (essentially all of them, plus a lot of duplicates). Another 815 connections were via Quora. Only 26 connections could be traced to Facebook profiles. The rest were to blogs and miscellaneous sites.</p>
<p>Google social search showed me nothing a standard Google search wouldn't display; the only difference was that any non-social results were filtered out (and, of course, it showed me a list of people I'd never heard of before).</p>
<p>So this is what Facebook is upset about? Really?</p>
<p>According to <a href="http://www.thedailybeast.com/blogs-and-stories/2011-05-12/facebook-busted-in-clumsy-smear-attempt-on-google/#" target="_blank">The Daily Beast's Dan Lyons</a>, who managed to get Facebook to confess to hiring Burson-Marsteller to slime Google, Facebook is peeved Google has figured out a way to access some of its data:</p>
<blockquote readability="13">&#13;
<p><em>Confronted with evidence, a Facebook spokesman last night confirmed that Facebook hired Burson, citing two reasons: First, because it believes Google is doing some things in social networking that raise privacy concerns; second, and perhaps more important, because Facebook resents Google's attempts to use Facebook data in its own social-networking service.</em></p>&#13;
</blockquote>
<p>Here's the deal: Facebook is running its own private little Internet on the greater public Internet. Facebook likes its little walled garden because it's got a captive audience for its advertisers. At the same time, though, Facebook also likes to get the oodles of traffic Google brings. So it lets just a little data out to draw people in.</p>
<p>That's why you can find someone's Facebook's profile via Google, and maybe one or two photos. But you can't Google someone's Facebook status updates the way you can Google the same person's tweets, or find all the photos they've posted. Facebook won't allow it.</p>
<p>This fight is all about how much of that Facebook data leaks out onto Google. Facebook is afraid <a href="http://www.pcworld.com/article/222143/a_sharing_site_called_circles_hey_google_its_been_done.html?tk=rel_news" target="_blank">if Google Social Circles catches on,</a> people will use it (and not Facebook) to make new connections.</p>
<p>As it turns out, I discovered a handful of cool web sites and people I might want to friend via Google's Social Search. Let's compare this to Facebook, where every time I log on it tosses up two new strangers for me to friend, simply because we have at least one friend in common (and sometimes, not even that). Which is more invasive?</p>
<p>I asked my personal Facebook spokesmodel to provide examples of the potential harm Google Social Circles could do to someone's privacy. I'll update this post if they respond. But I'm really not expecting much.</p>
<p><a href="http://www.itworld.com/blogs/dantynan" target="_blank"><em>TY4NS blogger Dan Tynan</em></a> <em>believes that on the scale of relative evil, cancelling Firefly far outweighs anything Google has done so far. Visit his snarky humor blog <a href="http://www.esarcasm.com/" target="_blank">(eSarcasm)</a> or follow him on Twitter:</em> <a href="http://twitter.com/#%21/Tynan_on_Tech" target="_blank"><em>@tynan_on_tech</em></a><em>.</em></p>
</div><p><a href="http://itworld.com/" target="_blank"><img src="http://images.pcworld.com/images/source/itworld_logo.gif" align="left" class="c6"/></a><br clear="all"/>&#13;
For more computing news, visit <a href="http://itworld.com/" target="_blank">ITworld</a>. Story copyright © 2011 ITworld Inc. All rights reserved.</p>

Open in new window


<div class="blogdescriptionouter blogdescription" readability="33">

<p><strong>by Jess McCabe // 8 May 2011, 13:05</strong></p>
</div>
<p><img src="http://www.thefword.org.uk/blog/images/oldbaileyladyjustice.jpg" alt="oldbaileyladyjustice.jpg" width="300" height="300" class="right" />One in six specialist domestic violence courts will be shut down as a result of the cuts, <a href="http://www.lawgazette.co.uk/news/domestic-violence-courts-close">the Law Society Gazette</a> is reporting:</p>
<blockquote readability="24">&#13;
<p>Shadow justice minister Andy Slaughter has tabled a series of parliamentary questions to justice secretary Kenneth Clarke on the impact of the closures, due to be answered this week.</p>&#13;
<p>The Specialist Domestic Violence Court (SDVC) was introduced in 2005 to make it easier for victims to give evidence and bring more offenders to justice.</p>&#13;
<p>The scheme was hailed as an immediate success by government and court users, and within four years 127 had been established.</p>&#13;
<p>However, 23 SDVCs are among the 142 courts that the Ministry of Justice plans to close during this parliament as part of its cost-cutting measures.</p>&#13;
<p>Slaughter said: ‘These specialist courts are a proven success at getting domestic violence cases through trial by supporting vulnerable women.</p>&#13;
<p>'Closing one in six is further evidence that the government is targeting women and gives the lie to its claim that it is only outdated courts that are being closed.’</p>&#13;
</blockquote>
<p>The Law Society <a href="http://www.lawgazette.co.uk/news/domestic-violence-courts-close">also quotes</a> a representative from Refuge talking about the impact of the cuts and goes into more details. A Ministry of Justice press officer is quoted saying the "services" provided by these courts will continue, even if the court that housed them has been shut down, but it will definitely be interesting to see what kind of assurances Ken Clarke can come up with on this: on the face of it, yet another example of the cuts being directed at the most vulnerable.</p>
<p><em>Photo of Old Bailey by <a href="http://www.flickr.com/photos/steinsky/3373548180/">Joe Dunkley</a>, shared on Flickr under a Creative Commons license</em></p>
<p class="articlemetadata"><a href="http://www.thefword.org.uk/blog/2011/05/domestic_violence_courts_face_closure" title="Permanent link to this article">Permalink</a> // Tags: <a href="http://www.thefword.org.uk/blog/search?tag=cuts" title="Articles about cuts">cuts</a>, <a href="http://www.thefword.org.uk/blog/search?tag=domestic%20violence" title="Articles about domestic violence">domestic violence</a>, <a href="http://www.thefword.org.uk/blog/search?tag=Tories" title="Articles about Tories">Tories</a></p>

Open in new window


&#13;
&#13;
<p><img src="http://9.mshcdn.com/wp-content/uploads/2011/05/Coke-Image-Mahshable-360.jpg" alt="" title="Coke Image Mahshable 360" width="225" height="" class="alignright size-full wp-image-617259"/>Earlier this week, we <a href="http://mashable.com/2011/05/11/tag-facebook-pages/">asked</a> if you’ve ever had the urge to tag that can of Coke you’re holding in a <a href="http://mashable.com/follow/topics/facebook/">Facebook</a> picture. Apparently, many of you have.</p>&#13;
<p><a href="http://www.facebook.com/cocacola" target="_blank">Coca-Cola’s Facebook Page</a> now sports several pictures of fans posing with tagged Coke cans. Coke had encouraged fans to do so within hours of Facebook’s announcement last week. <a href="http://www.facebook.com/Starbucks" target="_blank">Starbucks</a>‘s and <a href="http://www.facebook.com/zappos" target="_blank">Zappos</a>‘s Facebook Pages have also posted pictures of fans with tagged products.</p>&#13;
<p>Facebook added the functionality on March 11. Such tagged photos appear in the Photos tab of a Page, rather than that Page’s wall. While such tagging is so far voluntary, <em>The Atlantic</em>’s Nicholas Jackson <a href="http://www.theatlantic.com/technology/archive/2011/05/facebook-opens-photo-feature-to-product-placement/238757/" target="_blank">speculated</a> that Facebook could monetize the feature by making it automatic. Instead of tagging the photo yourself, Coca-Cola could do it for you, resulting in what is, in effect, real-life product placement.</p>&#13;
<p>What do you think? Is this an increase in functionality or another example of Facebook grafting commerce onto social interactions? Let us know in the comments.</p>&#13;
&#13;
&#13;

Open in new window

Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
I just wanted to explain that I am already stripping the XML and the above examples show the contents within the Item_Contents tag of the XML. So all I need to strip html for is the above data that you see.
Most Valuable Expert 2011
Top Expert 2016

Commented:
I thought you had an RSS feed.  RSS is a specialized subset of XML, but it looks like there is no XML in there, so it's not an RSS feed any more.  Can you tell us what you want to do with these data strings?  Maybe a before-and-after example would be helpful.  Thanks, ~Ray

Author

Commented:
Sure. Sorry for the confusion. Here is what I am looking for:

Before:
<div readability="137.61176152738">
<p><span class="image rtsm"><img src="http://zapp5.staticworld.net/images/article/2011/05/google_facebook_logos180-5173572.jpg" alt="" height="119" width="180"/></span>This just in: Facebook and Google <a href="http://www.pcworld.com/article/227903/facebooks_antigoogle_efforts_get_muddier.html?tk=rel_news" target="_blank">don't like each other</a> much. How do we know this? Because Facebook hired a very expensive PR firm to <a href="http://www.itworld.com/internet/164619/blogger-blows-lid-secret-facebook-scheme-smear-google" target="_blank">plant negative stories about Google</a> in the press.</p>
<p>In case you missed this story, here's the Readers Digest version: Facebook hired PR mavens-to-the-stars Burson-Marsteller to paint Google Social Circles <a href="http://pastebin.com/zaeTeJeJ" target="_blank">as the most evil thing</a> to happen since Fox Networks cancelled "Firefly." From Burson-Marsteller's email pitch:</p>
<blockquote readability="9">&#13;
<p><em>Google is collecting, storing and mining millions of people's personal information from a number of different online services and sharing it without the knowledge, consent or control of the people involved.</em></p>&#13;
</blockquote>
<p>The problem: Facebook did this in the <a href="http://www.infoworld.com/t/cringely/facebooks-failed-google-smear-stupidity-squared-979" target="_blank">stupidest way possible</a>, and tried to do it in secret. Didn't work. Oops.</p>
<p><strong>[ See also:</strong> <a href="http://www.itworld.com/security/164069/would-you-trust-hbgary-i-don-t" target="_blank"><strong>Would you trust HBGary? I don't.</strong></a> <strong>]</strong></p>
<p>Got this official comment from a Facebook spokeshuman yesterday:</p>
<blockquote readability="15.34833869239">&#13;
<p><em>No 'smear' campaign was authorized or intended. Instead, we wanted third parties to verify that people did not approve of the collection and use of information from their accounts on Facebook and other services for inclusion in Google Social Circles -- just as Facebook did not approve of use or collection for this purpose. We engaged Burson-Marsteller to focus attention on this issue, using publicly available information that could be independently verified by any media organization or analyst. The issues are serious and we should have presented them in a serious and transparent way.</em></p>&#13;
<p><em>You and your readers can look at the feature and decide if they have approved of this collection and use of information by clicking here when their Google account is open:</em> <a href="http://www.google.com/s2/search/social"><em>http://www.google.com/s2/search/social</em></a><em>. Of course, people who do not have Gmail accounts are still included in this collection but they have no way to view or control it.</em></p>&#13;
</blockquote>
<p>OK, maybe Facebook had a point. I decided to check it out.</p>
<p>I clicked the link, which brought me to a Google Social Search page. This told me I had 31 direct connections via Google Chat, another 990 via Google Profiles or Connected accounts, and some 2,858 "secondary connections." These would be people I don't necessarily know but who are connected to the people I do know.</p>
<p>Presumably, this would be where the privacy violations that so vexed Facebook would appear. After all, many of them are complete strangers to me; why should I know anything about them?</p>
<p>Only one problem: I couldn't find any vexing privacy violations. Take a look at what my Google Search Profile looks like:</p>
<p><span class="image large"><img src="http://www.itworld.com/sites/default/files/images/google%20social%20search%20-%20dan%20tynan%20paths.jpg" alt="google social search results" height="207" width="589"/><span class="artCaption">google social search results</span></span><strong>google social search results</strong></p>
<p>Shocking, ain't it? This is about as detailed as <a href="http://www.pcworld.com/article/222012/google_circles_looms_but_do_googles_nerds_get_social.html?tk=rel_news" target="_blank">Google Social Circles</a> gets, and it's only this detailed because I voluntarily added all these links to my public Google Profile. There's nothing in there that isn't already public information, available to anyone with enough gray matter to type a query into a search engine.</p>
<p>Now for some stats: Twitter accounted for 4,192 of my social search connections (essentially all of them, plus a lot of duplicates). Another 815 connections were via Quora. Only 26 connections could be traced to Facebook profiles. The rest were to blogs and miscellaneous sites.</p>
<p>Google social search showed me nothing a standard Google search wouldn't display; the only difference was that any non-social results were filtered out (and, of course, it showed me a list of people I'd never heard of before).</p>
<p>So this is what Facebook is upset about? Really?</p>
<p>According to <a href="http://www.thedailybeast.com/blogs-and-stories/2011-05-12/facebook-busted-in-clumsy-smear-attempt-on-google/#" target="_blank">The Daily Beast's Dan Lyons</a>, who managed to get Facebook to confess to hiring Burson-Marsteller to slime Google, Facebook is peeved Google has figured out a way to access some of its data:</p>
<blockquote readability="13">&#13;
<p><em>Confronted with evidence, a Facebook spokesman last night confirmed that Facebook hired Burson, citing two reasons: First, because it believes Google is doing some things in social networking that raise privacy concerns; second, and perhaps more important, because Facebook resents Google's attempts to use Facebook data in its own social-networking service.</em></p>&#13;
</blockquote>
<p>Here's the deal: Facebook is running its own private little Internet on the greater public Internet. Facebook likes its little walled garden because it's got a captive audience for its advertisers. At the same time, though, Facebook also likes to get the oodles of traffic Google brings. So it lets just a little data out to draw people in.</p>
<p>That's why you can find someone's Facebook's profile via Google, and maybe one or two photos. But you can't Google someone's Facebook status updates the way you can Google the same person's tweets, or find all the photos they've posted. Facebook won't allow it.</p>
<p>This fight is all about how much of that Facebook data leaks out onto Google. Facebook is afraid <a href="http://www.pcworld.com/article/222143/a_sharing_site_called_circles_hey_google_its_been_done.html?tk=rel_news" target="_blank">if Google Social Circles catches on,</a> people will use it (and not Facebook) to make new connections.</p>
<p>As it turns out, I discovered a handful of cool web sites and people I might want to friend via Google's Social Search. Let's compare this to Facebook, where every time I log on it tosses up two new strangers for me to friend, simply because we have at least one friend in common (and sometimes, not even that). Which is more invasive?</p>
<p>I asked my personal Facebook spokesmodel to provide examples of the potential harm Google Social Circles could do to someone's privacy. I'll update this post if they respond. But I'm really not expecting much.</p>
<p><a href="http://www.itworld.com/blogs/dantynan" target="_blank"><em>TY4NS blogger Dan Tynan</em></a> <em>believes that on the scale of relative evil, cancelling Firefly far outweighs anything Google has done so far. Visit his snarky humor blog <a href="http://www.esarcasm.com/" target="_blank">(eSarcasm)</a> or follow him on Twitter:</em> <a href="http://twitter.com/#%21/Tynan_on_Tech" target="_blank"><em>@tynan_on_tech</em></a><em>.</em></p>
</div><p><a href="http://itworld.com/" target="_blank"><img src="http://images.pcworld.com/images/source/itworld_logo.gif" align="left" class="c6"/></a><br clear="all"/>&#13;
For more computing news, visit <a href="http://itworld.com/" target="_blank">ITworld</a>. Story copyright © 2011 ITworld Inc. All rights reserved.</p>

Open in new window


After:
This just in: Facebook and Google don't like each other much. How do we know this? Because Facebook hired a very expensive PR firm to plant negative stories about Google in the press.
In case you missed this story, here's the Readers Digest version: Facebook hired PR mavens-to-the-stars Burson-Marsteller to paint Google Social Circles as the most evil thing to happen since Fox Networks cancelled "Firefly." From Burson-Marsteller's email pitch:

Google is collecting, storing and mining millions of people's personal information from a number of different online services and sharing it without the knowledge, consent or control of the people involved.

The problem: Facebook did this in the stupidest way possible, and tried to do it in secret. Didn't work. Oops.
[ See also: Would you trust HBGary? I don't. ]
Got this official comment from a Facebook spokeshuman yesterday:

No 'smear' campaign was authorized or intended. Instead, we wanted third parties to verify that people did not approve of the collection and use of information from their accounts on Facebook and other services for inclusion in Google Social Circles -- just as Facebook did not approve of use or collection for this purpose. We engaged Burson-Marsteller to focus attention on this issue, using publicly available information that could be independently verified by any media organization or analyst. The issues are serious and we should have presented them in a serious and transparent way.
You and your readers can look at the feature and decide if they have approved of this collection and use of information by clicking here when their Google account is open: http://www.google.com/s2/search/social. Of course, people who do not have Gmail accounts are still included in this collection but they have no way to view or control it.

OK, maybe Facebook had a point. I decided to check it out.
I clicked the link, which brought me to a Google Social Search page. This told me I had 31 direct connections via Google Chat, another 990 via Google Profiles or Connected accounts, and some 2,858 "secondary connections." These would be people I don't necessarily know but who are connected to the people I do know.
Presumably, this would be where the privacy violations that so vexed Facebook would appear. After all, many of them are complete strangers to me; why should I know anything about them?
Only one problem: I couldn't find any vexing privacy violations. Take a look at what my Google Search Profile looks like:
google social search resultsgoogle social search results
Shocking, ain't it? This is about as detailed as Google Social Circles gets, and it's only this detailed because I voluntarily added all these links to my public Google Profile. There's nothing in there that isn't already public information, available to anyone with enough gray matter to type a query into a search engine.
Now for some stats: Twitter accounted for 4,192 of my social search connections (essentially all of them, plus a lot of duplicates). Another 815 connections were via Quora. Only 26 connections could be traced to Facebook profiles. The rest were to blogs and miscellaneous sites.
Google social search showed me nothing a standard Google search wouldn't display; the only difference was that any non-social results were filtered out (and, of course, it showed me a list of people I'd never heard of before).
So this is what Facebook is upset about? Really?
According to The Daily Beast's Dan Lyons, who managed to get Facebook to confess to hiring Burson-Marsteller to slime Google, Facebook is peeved Google has figured out a way to access some of its data:

Confronted with evidence, a Facebook spokesman last night confirmed that Facebook hired Burson, citing two reasons: First, because it believes Google is doing some things in social networking that raise privacy concerns; second, and perhaps more important, because Facebook resents Google's attempts to use Facebook data in its own social-networking service.

Here's the deal: Facebook is running its own private little Internet on the greater public Internet. Facebook likes its little walled garden because it's got a captive audience for its advertisers. At the same time, though, Facebook also likes to get the oodles of traffic Google brings. So it lets just a little data out to draw people in.
That's why you can find someone's Facebook's profile via Google, and maybe one or two photos. But you can't Google someone's Facebook status updates the way you can Google the same person's tweets, or find all the photos they've posted. Facebook won't allow it.
This fight is all about how much of that Facebook data leaks out onto Google. Facebook is afraid if Google Social Circles catches on, people will use it (and not Facebook) to make new connections.
As it turns out, I discovered a handful of cool web sites and people I might want to friend via Google's Social Search. Let's compare this to Facebook, where every time I log on it tosses up two new strangers for me to friend, simply because we have at least one friend in common (and sometimes, not even that). Which is more invasive?
I asked my personal Facebook spokesmodel to provide examples of the potential harm Google Social Circles could do to someone's privacy. I'll update this post if they respond. But I'm really not expecting much.
TY4NS blogger Dan Tynan believes that on the scale of relative evil, cancelling Firefly far outweighs anything Google has done so far. Visit his snarky humor blog (eSarcasm) or follow him on Twitter: @tynan_on_tech.

For more computing news, visit ITworld. Story copyright © 2011 ITworld Inc. All rights reserved.

Open in new window


Before:
<div class="blogdescriptionouter blogdescription" readability="33">

<p><strong>by Jess McCabe // 8 May 2011, 13:05</strong></p>
</div>
<p><img src="http://www.thefword.org.uk/blog/images/oldbaileyladyjustice.jpg" alt="oldbaileyladyjustice.jpg" width="300" height="300" class="right" />One in six specialist domestic violence courts will be shut down as a result of the cuts, <a href="http://www.lawgazette.co.uk/news/domestic-violence-courts-close">the Law Society Gazette</a> is reporting:</p>
<blockquote readability="24">&#13;
<p>Shadow justice minister Andy Slaughter has tabled a series of parliamentary questions to justice secretary Kenneth Clarke on the impact of the closures, due to be answered this week.</p>&#13;
<p>The Specialist Domestic Violence Court (SDVC) was introduced in 2005 to make it easier for victims to give evidence and bring more offenders to justice.</p>&#13;
<p>The scheme was hailed as an immediate success by government and court users, and within four years 127 had been established.</p>&#13;
<p>However, 23 SDVCs are among the 142 courts that the Ministry of Justice plans to close during this parliament as part of its cost-cutting measures.</p>&#13;
<p>Slaughter said: ‘These specialist courts are a proven success at getting domestic violence cases through trial by supporting vulnerable women.</p>&#13;
<p>'Closing one in six is further evidence that the government is targeting women and gives the lie to its claim that it is only outdated courts that are being closed.’</p>&#13;
</blockquote>
<p>The Law Society <a href="http://www.lawgazette.co.uk/news/domestic-violence-courts-close">also quotes</a> a representative from Refuge talking about the impact of the cuts and goes into more details. A Ministry of Justice press officer is quoted saying the "services" provided by these courts will continue, even if the court that housed them has been shut down, but it will definitely be interesting to see what kind of assurances Ken Clarke can come up with on this: on the face of it, yet another example of the cuts being directed at the most vulnerable.</p>
<p><em>Photo of Old Bailey by <a href="http://www.flickr.com/photos/steinsky/3373548180/">Joe Dunkley</a>, shared on Flickr under a Creative Commons license</em></p>
<p class="articlemetadata"><a href="http://www.thefword.org.uk/blog/2011/05/domestic_violence_courts_face_closure" title="Permanent link to this article">Permalink</a> // Tags: <a href="http://www.thefword.org.uk/blog/search?tag=cuts" title="Articles about cuts">cuts</a>, <a href="http://www.thefword.org.uk/blog/search?tag=domestic%20violence" title="Articles about domestic violence">domestic violence</a>, <a href="http://www.thefword.org.uk/blog/search?tag=Tories" title="Articles about Tories">Tories</a></p>

Open in new window


After:
by Jess McCabe // 8 May 2011, 13:05

One in six specialist domestic violence courts will be shut down as a result of the cuts, the Law Society Gazette is reporting:

Shadow justice minister Andy Slaughter has tabled a series of parliamentary questions to justice secretary Kenneth Clarke on the impact of the closures, due to be answered this week.
The Specialist Domestic Violence Court (SDVC) was introduced in 2005 to make it easier for victims to give evidence and bring more offenders to justice.
The scheme was hailed as an immediate success by government and court users, and within four years 127 had been established.
However, 23 SDVCs are among the 142 courts that the Ministry of Justice plans to close during this parliament as part of its cost-cutting measures.
Slaughter said: ‘These specialist courts are a proven success at getting domestic violence cases through trial by supporting vulnerable women.
'Closing one in six is further evidence that the government is targeting women and gives the lie to its claim that it is only outdated courts that are being closed.’

The Law Society also quotes a representative from Refuge talking about the impact of the cuts and goes into more details. A Ministry of Justice press officer is quoted saying the "services" provided by these courts will continue, even if the court that housed them has been shut down, but it will definitely be interesting to see what kind of assurances Ken Clarke can come up with on this: on the face of it, yet another example of the cuts being directed at the most vulnerable.
Photo of Old Bailey by Joe Dunkley, shared on Flickr under a Creative Commons license
Permalink // Tags: cuts, domestic violence, Tories

Open in new window

Most Valuable Expert 2011
Top Expert 2016

Commented:
That looks like strip_tags() will do the job.  You might throw in nl2br() after strip_tags, depending on how you intend to format the output.
http://php.net/manual/en/function.strip-tags.php
http://php.net/manual/en/function.nl2br.php
Erdinç Güngör ÇorbacıPHP Development Team Leader

Commented:
Sorry for my carelessness .. here is the function which i mentioned

 
<?php 
     function remove_HTML($s , $keep = '' , $expand = 'script|style|noframes|select|option'){
         /**///prep the string
         $s = ' ' . $s;
         
         /**///initialize keep tag logic
         if(strlen($keep) > 0){
             $k = explode('|',$keep);
             for($i=0;$i<count($k);$i++){
                 $s = str_replace('<' . $k[$i],'[{(' . $k[$i],$s);
                 $s = str_replace('</' . $k[$i],'[{(/' . $k[$i],$s);
             }
         }
         
         //begin removal
         /**///remove comment blocks
         while(stripos($s,'<!--') > 0){
             $pos[1] = stripos($s,'<!--');
             $pos[2] = stripos($s,'-->', $pos[1]);
             $len[1] = $pos[2] - $pos[1] + 3;
             $x = substr($s,$pos[1],$len[1]);
             $s = str_replace($x,'',$s);
         }
         
         /**///remove tags with content between them
         if(strlen($expand) > 0){
             $e = explode('|',$expand);
             for($i=0;$i<count($e);$i++){
                 while(stripos($s,'<' . $e[$i]) > 0){
                     $len[1] = strlen('<' . $e[$i]);
                     $pos[1] = stripos($s,'<' . $e[$i]);
                     $pos[2] = stripos($s,$e[$i] . '>', $pos[1] + $len[1]);
                     $len[2] = $pos[2] - $pos[1] + $len[1];
                     $x = substr($s,$pos[1],$len[2]);
                     $s = str_replace($x,'',$s);
                 }
             }
         }
         
         /**///remove remaining tags
         while(stripos($s,'<') > 0){
             $pos[1] = stripos($s,'<');
             $pos[2] = stripos($s,'>', $pos[1]);
             $len[1] = $pos[2] - $pos[1] + 1;
             $x = substr($s,$pos[1],$len[1]);
             $s = str_replace($x,'',$s);
         }
         
         /**///finalize keep tag
         for($i=0;$i<count($k);$i++){
             $s = str_replace('[{(' . $k[$i],'<' . $k[$i],$s);
             $s = str_replace('[{(/' . $k[$i],'</' . $k[$i],$s);
         }
         
         return trim($s);
     }
?>

Open in new window

Most Valuable Expert 2011
Top Expert 2016
Commented:
This gets to 99% the same.  It appears that the &#13; entities are the only differences.   See it in action here:
http://www.laprbass.com/RAY_temp_nainil.php

Best regards, ~Ray
<?php // RAY_temp_nainil.php
error_reporting(E_ALL);

$original = <<<ORIGINAL
<div class="blogdescriptionouter blogdescription" readability="33">

<p><strong>by Jess McCabe // 8 May 2011, 13:05</strong></p>
</div>
<p><img src="http://www.thefword.org.uk/blog/images/oldbaileyladyjustice.jpg" alt="oldbaileyladyjustice.jpg" width="300" height="300" class="right" />One in six specialist domestic violence courts will be shut down as a result of the cuts, <a href="http://www.lawgazette.co.uk/news/domestic-violence-courts-close">the Law Society Gazette</a> is reporting:</p>
<blockquote readability="24">&#13;
<p>Shadow justice minister Andy Slaughter has tabled a series of parliamentary questions to justice secretary Kenneth Clarke on the impact of the closures, due to be answered this week.</p>&#13;
<p>The Specialist Domestic Violence Court (SDVC) was introduced in 2005 to make it easier for victims to give evidence and bring more offenders to justice.</p>&#13;
<p>The scheme was hailed as an immediate success by government and court users, and within four years 127 had been established.</p>&#13;
<p>However, 23 SDVCs are among the 142 courts that the Ministry of Justice plans to close during this parliament as part of its cost-cutting measures.</p>&#13;
<p>Slaughter said: ‘These specialist courts are a proven success at getting domestic violence cases through trial by supporting vulnerable women.</p>&#13;
<p>'Closing one in six is further evidence that the government is targeting women and gives the lie to its claim that it is only outdated courts that are being closed.’</p>&#13;
</blockquote>
<p>The Law Society <a href="http://www.lawgazette.co.uk/news/domestic-violence-courts-close">also quotes</a> a representative from Refuge talking about the impact of the cuts and goes into more details. A Ministry of Justice press officer is quoted saying the "services" provided by these courts will continue, even if the court that housed them has been shut down, but it will definitely be interesting to see what kind of assurances Ken Clarke can come up with on this: on the face of it, yet another example of the cuts being directed at the most vulnerable.</p>
<p><em>Photo of Old Bailey by <a href="http://www.flickr.com/photos/steinsky/3373548180/">Joe Dunkley</a>, shared on Flickr under a Creative Commons license</em></p>
<p class="articlemetadata"><a href="http://www.thefword.org.uk/blog/2011/05/domestic_violence_courts_face_closure" title="Permanent link to this article">Permalink</a> // Tags: <a href="http://www.thefword.org.uk/blog/search?tag=cuts" title="Articles about cuts">cuts</a>, <a href="http://www.thefword.org.uk/blog/search?tag=domestic%20violence" title="Articles about domestic violence">domestic violence</a>, <a href="http://www.thefword.org.uk/blog/search?tag=Tories" title="Articles about Tories">Tories</a></p>
ORIGINAL;

$finished = <<<FINISHED
by Jess McCabe // 8 May 2011, 13:05

One in six specialist domestic violence courts will be shut down as a result of the cuts, the Law Society Gazette is reporting:

Shadow justice minister Andy Slaughter has tabled a series of parliamentary questions to justice secretary Kenneth Clarke on the impact of the closures, due to be answered this week.
The Specialist Domestic Violence Court (SDVC) was introduced in 2005 to make it easier for victims to give evidence and bring more offenders to justice.
The scheme was hailed as an immediate success by government and court users, and within four years 127 had been established.
However, 23 SDVCs are among the 142 courts that the Ministry of Justice plans to close during this parliament as part of its cost-cutting measures.
Slaughter said: ‘These specialist courts are a proven success at getting domestic violence cases through trial by supporting vulnerable women.
'Closing one in six is further evidence that the government is targeting women and gives the lie to its claim that it is only outdated courts that are being closed.’

The Law Society also quotes a representative from Refuge talking about the impact of the cuts and goes into more details. A Ministry of Justice press officer is quoted saying the "services" provided by these courts will continue, even if the court that housed them has been shut down, but it will definitely be interesting to see what kind of assurances Ken Clarke can come up with on this: on the face of it, yet another example of the cuts being directed at the most vulnerable.
Photo of Old Bailey by Joe Dunkley, shared on Flickr under a Creative Commons license
Permalink // Tags: cuts, domestic violence, Tories
FINISHED;

$new = strip_tags($original);

// SHOW THE ORIGINAL AND THE WORK PRODUCT
echo $original;
echo "<br/><br/>";
echo $finished;
echo "<br/><br/>";
echo $new;
echo "<br/><br/>";

// TEST THE WORK PRODUCT
if ($new == $finished)
{
    echo "Same.";
}
else
{
    $x = similar_text($finished, $new, $percent);
    $p = number_format($percent);
    echo $p . "% Same.";
}

Open in new window

Author

Commented:
@erdincgc

Here is what I receive:
( ! ) Notice: Undefined variable: k in C:\wamp\www\test\striphtml.php on line 50

Can you show me a working example of your code?

My code:
<?php 
     function remove_HTML($s , $keep = '' , $expand = 'script|style|noframes|select|option'){
         /**///prep the string
         $s = ' ' . $s;
         
         /**///initialize keep tag logic
         if(strlen($keep) > 0){
             $k = explode('|',$keep);
             for($i=0;$i<count($k);$i++){
                 $s = str_replace('<' . $k[$i],'[{(' . $k[$i],$s);
                 $s = str_replace('</' . $k[$i],'[{(/' . $k[$i],$s);
             }
         }
         
         //begin removal
         /**///remove comment blocks
         while(stripos($s,'<!--') > 0){
             $pos[1] = stripos($s,'<!--');
             $pos[2] = stripos($s,'-->', $pos[1]);
             $len[1] = $pos[2] - $pos[1] + 3;
             $x = substr($s,$pos[1],$len[1]);
             $s = str_replace($x,'',$s);
         }
         
         /**///remove tags with content between them
         if(strlen($expand) > 0){
             $e = explode('|',$expand);
             for($i=0;$i<count($e);$i++){
                 while(stripos($s,'<' . $e[$i]) > 0){
                     $len[1] = strlen('<' . $e[$i]);
                     $pos[1] = stripos($s,'<' . $e[$i]);
                     $pos[2] = stripos($s,$e[$i] . '>', $pos[1] + $len[1]);
                     $len[2] = $pos[2] - $pos[1] + $len[1];
                     $x = substr($s,$pos[1],$len[2]);
                     $s = str_replace($x,'',$s);
                 }
             }
         }
         
         /**///remove remaining tags
         while(stripos($s,'<') > 0){
             $pos[1] = stripos($s,'<');
             $pos[2] = stripos($s,'>', $pos[1]);
             $len[1] = $pos[2] - $pos[1] + 1;
             $x = substr($s,$pos[1],$len[1]);
             $s = str_replace($x,'',$s);
         }
         
         /**///finalize keep tag
         for($i=0;$i<count($k);$i++){
             $s = str_replace('[{(' . $k[$i],'<' . $k[$i],$s);
             $s = str_replace('[{(/' . $k[$i],'</' . $k[$i],$s);
         }
         
         return trim($s);
     }

$original = <<<ORIGINAL
<div class="blogdescriptionouter blogdescription" readability="33">

<p><strong>by Jess McCabe // 8 May 2011, 13:05</strong></p>
</div>
<p><img src="http://www.thefword.org.uk/blog/images/oldbaileyladyjustice.jpg" alt="oldbaileyladyjustice.jpg" width="300" height="300" class="right" />One in six specialist domestic violence courts will be shut down as a result of the cuts, <a href="http://www.lawgazette.co.uk/news/domestic-violence-courts-close">the Law Society Gazette</a> is reporting:</p>
<blockquote readability="24">&#13;
<p>Shadow justice minister Andy Slaughter has tabled a series of parliamentary questions to justice secretary Kenneth Clarke on the impact of the closures, due to be answered this week.</p>&#13;
<p>The Specialist Domestic Violence Court (SDVC) was introduced in 2005 to make it easier for victims to give evidence and bring more offenders to justice.</p>&#13;
<p>The scheme was hailed as an immediate success by government and court users, and within four years 127 had been established.</p>&#13;
<p>However, 23 SDVCs are among the 142 courts that the Ministry of Justice plans to close during this parliament as part of its cost-cutting measures.</p>&#13;
<p>Slaughter said: ‘These specialist courts are a proven success at getting domestic violence cases through trial by supporting vulnerable women.</p>&#13;
<p>'Closing one in six is further evidence that the government is targeting women and gives the lie to its claim that it is only outdated courts that are being closed.’</p>&#13;
</blockquote>
<p>The Law Society <a href="http://www.lawgazette.co.uk/news/domestic-violence-courts-close">also quotes</a> a representative from Refuge talking about the impact of the cuts and goes into more details. A Ministry of Justice press officer is quoted saying the "services" provided by these courts will continue, even if the court that housed them has been shut down, but it will definitely be interesting to see what kind of assurances Ken Clarke can come up with on this: on the face of it, yet another example of the cuts being directed at the most vulnerable.</p>
<p><em>Photo of Old Bailey by <a href="http://www.flickr.com/photos/steinsky/3373548180/">Joe Dunkley</a>, shared on Flickr under a Creative Commons license</em></p>
<p class="articlemetadata"><a href="http://www.thefword.org.uk/blog/2011/05/domestic_violence_courts_face_closure" title="Permanent link to this article">Permalink</a> // Tags: <a href="http://www.thefword.org.uk/blog/search?tag=cuts" title="Articles about cuts">cuts</a>, <a href="http://www.thefword.org.uk/blog/search?tag=domestic%20violence" title="Articles about domestic violence">domestic violence</a>, <a href="http://www.thefword.org.uk/blog/search?tag=Tories" title="Articles about Tories">Tories</a></p>
ORIGINAL;

$myresult = remove_HTML($original , $keep = '' , $expand = 'script|style|noframes|select|option');
echo $myresult;


?>

Open in new window

Erdinç Güngör ÇorbacıPHP Development Team Leader
Commented:
Notice: Undefined variable k  is just a notice for  variable k is being tried to reach without any assignment or definition.
You can close NOTICE errors or define variables before using or check if they are defined or not before using. But as i told this is just a notice and generally notices wont shown to the end users by servers.

Anyway  here is the new code that has $k defined previously;

<?php 
     function remove_HTML($s , $keep = '' , $expand = 'script|style|noframes|select|option'){
         /**///prep the string
         $s = ' ' . $s;
         $k =array();
         /**///initialize keep tag logic
         if(strlen($keep) > 0){
             $k = explode('|',$keep);
             for($i=0;$i<count($k);$i++){
                 $s = str_replace('<' . $k[$i],'[{(' . $k[$i],$s);
                 $s = str_replace('</' . $k[$i],'[{(/' . $k[$i],$s);
             }
         }

         if(!empty($k))
         {
         
         //begin removal
         /**///remove comment blocks
         while(stripos($s,'<!--') > 0){
             $pos[1] = stripos($s,'<!--');
             $pos[2] = stripos($s,'-->', $pos[1]);
             $len[1] = $pos[2] - $pos[1] + 3;
             $x = substr($s,$pos[1],$len[1]);
             $s = str_replace($x,'',$s);
         }
         
         /**///remove tags with content between them
         if(strlen($expand) > 0){
             $e = explode('|',$expand);
             for($i=0;$i<count($e);$i++){
                 while(stripos($s,'<' . $e[$i]) > 0){
                     $len[1] = strlen('<' . $e[$i]);
                     $pos[1] = stripos($s,'<' . $e[$i]);
                     $pos[2] = stripos($s,$e[$i] . '>', $pos[1] + $len[1]);
                     $len[2] = $pos[2] - $pos[1] + $len[1];
                     $x = substr($s,$pos[1],$len[2]);
                     $s = str_replace($x,'',$s);
                 }
             }
         }
         
         /**///remove remaining tags
         while(stripos($s,'<') > 0){
             $pos[1] = stripos($s,'<');
             $pos[2] = stripos($s,'>', $pos[1]);
             $len[1] = $pos[2] - $pos[1] + 1;
             $x = substr($s,$pos[1],$len[1]);
             $s = str_replace($x,'',$s);
         }
         
         /**///finalize keep tag
         for($i=0;$i<count($k);$i++){
             $s = str_replace('[{(' . $k[$i],'<' . $k[$i],$s);
             $s = str_replace('[{(/' . $k[$i],'</' . $k[$i],$s);
         }
         
         return trim($s);
         }
     }
?>

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial