strip-tags

How to strip tags in a safer way than using strip_tags function?

眉间皱痕 提交于 2019-12-01 16:00:44
问题 I'm having some problems using strip_tags PHP function when the string contains 'less than' and 'greater than' signs. For example: If I do: strip_tags("<span>some text <5ml and then >10ml some text </span>"); I'll get: some text 10ml some text But, obviously I want to get: some text <5ml and then >10ml some text Yes I know that I could use < and >, but I don't have chance to convert those characters into HTML entities since data is already stored as you can see in my example. What I'm looking

replace all but certain html tags with htmlspecialchars() in PHP?

末鹿安然 提交于 2019-12-01 11:50:44
问题 I would like to process my user input to allow only certain html tags, and replace the other ones by their html entities, as well as replace non-tag-characters. For example, if I only wanted to allow the <b> and the <a> tag, then allow_only("This is <b>bold</b> and this is <i>italic</i>. Moreover 2<3 and <a href='google.com'>this is a link</a>.","<b><a>"); should produce This is <b>bold</b> and this is <i>italic</i>. Moreover 2<3 and <a href='google.com'>this is a link</a>. How can I do this

PHP: strip_tags - remove only certain tags (and their contents)?

北城以北 提交于 2019-11-28 12:08:51
I use the strip_tags() function but I need to remove some tags (and all of their contents). for example : <div> <p class="test"> Test A </p> <span> Test B </span> <div> Test C </div> </div> Let's say, I need to get rid of the P and SPAN tags, and only keep : <div> <div> Test C </div> </div> strip_tags expects as a second parameter the tags that you want to KEEP. In this particular example I could use striptags($html, "<div>"); but the html I'm scraping and the tags that need to be removed are different all the time. I searched for hours for a function that suits my needs, but couldn't find

Problem using strip_tags in php [duplicate]

删除回忆录丶 提交于 2019-11-28 10:01:30
This question already has an answer here: strip_tags() … replace tags by space rather than deleting them 10 answers I have used strip_tags to remove html tags from the text. Example <h1>title of article</h1><div class="body">The content goes here......</div> outputs title of articleThe content goes here...... If you see the output title and body are joined(articleThe). I want to insert a space if the tag has been removed. Is this possible. I appreciate any help. Thanks. If all you want is to add a space where an opening tag directly follows a closing tag, you could do this: $html = preg

Is strip_tags() vulnerable to scripting attacks?

时光毁灭记忆、已成空白 提交于 2019-11-28 04:28:36
Is there a known XSS or other attack that makes it past a $content = "some HTML code"; $content = strip_tags($content); echo $content; ? The manual has a warning: This function does not modify any attributes on the tags that you allow using allowable_tags, including the style and onmouseover attributes that a mischievous user may abuse when posting text that will be shown to other users. but that is related to using the allowable_tags parameter only. With no allowed tags set , is strip_tags() vulnerable to any attack? Chris Shiflett seems to say it's safe: Use Mature Solutions When possible,

What is the MySQL query equivalent of PHP strip_tags?

依然范特西╮ 提交于 2019-11-27 07:52:30
I have a large database which contains records that have <a> tags in them and I would like to remove them. Of course there is the method where I create a PHP script that selects all, uses strip_tags and updates the database, but this takes a long time. So how can I do this with a simple (or complicated) MySQL query? I don't believe there's any efficient way to do this in MySQL alone. MySQL does have a REPLACE() function, but it can only replace constant strings, not patterns. You could possibly write a MySQL stored function to search for and replace tags, but at that point you're probably

PHP: strip_tags - remove only certain tags (and their contents)?

谁说我不能喝 提交于 2019-11-27 06:47:21
问题 I use the strip_tags() function but I need to remove some tags (and all of their contents). for example : <div> <p class="test"> Test A </p> <span> Test B </span> <div> Test C </div> </div> Let's say, I need to get rid of the P and SPAN tags, and only keep : <div> <div> Test C </div> </div> strip_tags expects as a second parameter the tags that you want to KEEP. In this particular example I could use striptags($html, "<div>"); but the html I'm scraping and the tags that need to be removed are

CKEditor strips inline attributes

怎甘沉沦 提交于 2019-11-27 05:14:29
I have been using CKEditor for some time and it has worked great. I've pretty much gotten rid of any problems that ive had but this one i cant seem to figure out. When i add inline attributes to elements for instance style = "color: #ff0;" on a <p></p> tag they are stripped out when i switch from wysiwyg to source view. No saving or submission is done and ckeditor is has been added to my site which is my own script. Any ideas as to what would cause this. All of the search results i can find correspond to this happening in Drupal but Drupal seems to be the problem not the editor in all

Problem using strip_tags in php [duplicate]

风流意气都作罢 提交于 2019-11-27 03:22:23
问题 This question already has an answer here: strip_tags() … replace tags by space rather than deleting them 10 answers I have used strip_tags to remove html tags from the text. Example <h1>title of article</h1><div class="body">The content goes here......</div> outputs title of articleThe content goes here...... If you see the output title and body are joined(articleThe). I want to insert a space if the tag has been removed. Is this possible. I appreciate any help. Thanks. 回答1: If all you want

Is strip_tags() vulnerable to scripting attacks?

那年仲夏 提交于 2019-11-27 00:26:17
问题 Is there a known XSS or other attack that makes it past a $content = "some HTML code"; $content = strip_tags($content); echo $content; ? The manual has a warning: This function does not modify any attributes on the tags that you allow using allowable_tags, including the style and onmouseover attributes that a mischievous user may abuse when posting text that will be shown to other users. but that is related to using the allowable_tags parameter only. With no allowed tags set , is strip_tags()