strip-tags

php strip_tags removing everything

筅森魡賤 提交于 2019-12-05 04:50:31
问题 I am using strip tags on user inputs to remove all possible tags but the strip_tags php function is also removing '<' even if not used in a tag. for example some user might use emoticon as such: >.< or <3 or this can even be used when algorithms etc. Are there any solution to allow the '<' on strip tags? 回答1: Problem is in this case $foo = "text >.<text" Try this expression (preg_replace with ims falgs): <\s*\/?[a-z0-9]+(\s*[a-z\-0-9]+)*(\s*[a-z\-0-9]+\="[^"]*")*\s*\/?> @edit: For example: <

strip_tags enough to remove HTML from string?

爷,独闯天下 提交于 2019-12-04 05:20:02
问题 The site user can sign-up on a site, and during sign-up he can provide a name. I want this name to be a valid name, and free of any HTML and other funky characters. Is strip_tags enough for this? 回答1: I find that there's no single function for idiot-proofing user inputs. Best to mix a few together: $val = trim($val); $val = strip_tags($val); $val = htmlentities($val, ENT_QUOTES, 'UTF-8'); // convert funky chars to html entities $pat = array("\r\n", "\n\r", "\n", "\r"); // remove returns $val

PHP, strip_tags stripping \n in text area. How to stop it?

喜欢而已 提交于 2019-12-04 03:33:13
问题 I would like to be able to accept \n or \r\n and convert them to <br /> for use in the page. Although when a user submits a text area with new paragraphs, the strip_tags function seems to strip them right out. Anything I can do to keep these in the string? Thanks!!! 回答1: You can use nl2br to add the BR line break element to line break character sequences: $html = nl2br($plain); Note that the BR elements are just added: nl2br("foo\nbar") === "foo\n<br />bar" And to prevent strip_tags to remove

php strip_tags removing everything

◇◆丶佛笑我妖孽 提交于 2019-12-03 18:03:24
I am using strip tags on user inputs to remove all possible tags but the strip_tags php function is also removing '<' even if not used in a tag. for example some user might use emoticon as such: >.< or <3 or this can even be used when algorithms etc. Are there any solution to allow the '<' on strip tags? Problem is in this case $foo = "text >.<text" Try this expression (preg_replace with ims falgs): <\s*\/?[a-z0-9]+(\s*[a-z\-0-9]+)*(\s*[a-z\-0-9]+\="[^"]*")*\s*\/?> @edit: For example: <?php $test = "text text text >.<asd text <div style=\"font-size:12px;\">text >.<in div</div> asd asd <b

Why doesn't strip_tags work in PHP?

亡梦爱人 提交于 2019-12-03 08:52:04
问题 I've got the following code: <?php echo strip_tags($firstArticle->introtext); ?> Where $firstArticle is a stdClass object: object(stdClass)[422] public 'link' => string '/maps101/index.php?option=com_content&view=article&id=57:greenlands-newest-iceberg&catid=11:geography-in-the-news' (length=125) public 'text' => string 'GREENLAND'S NEWEST ICEBERG' (length=26) public 'introtext' => string '<p>A giant chunk of ice calved off the Petermann Glacier on the northwest side of Greenland this summer.

Why doesn't strip_tags work in PHP?

不想你离开。 提交于 2019-12-02 22:47:15
I've got the following code: <?php echo strip_tags($firstArticle->introtext); ?> Where $firstArticle is a stdClass object: object(stdClass)[422] public 'link' => string '/maps101/index.php?option=com_content&view=article&id=57:greenlands-newest-iceberg&catid=11:geography-in-the-news' (length=125) public 'text' => string 'GREENLAND'S NEWEST ICEBERG' (length=26) public 'introtext' => string '<p>A giant chunk of ice calved off the Petermann Glacier on the northwest side of Greenland this summer. At nearly 100 square miles (260 sq. km) in size, four times the size of Manhattan, th' (length=206)

How to strip HTML tags using a black list in PHP?

那年仲夏 提交于 2019-12-02 16:44:55
问题 PHP strip_tags use a whitelist for skip some tags that you don't want were get rid. Anybody knows some implementation but using a blacklist instead of a whitelist? 回答1: A simple compound regex search would work (if this is still about your previous issue): $html = preg_replace("#</?(font|strike|marquee|blink|del)[^>]*>#i", "", $html); 回答2: Try this function posted by LWC on php.net - http://www.php.net/manual/en/function.strip-tags.php#96483 <?php function strip_only($str, $tags,

How to strip HTML tags using a black list in PHP?

筅森魡賤 提交于 2019-12-02 12:23:07
PHP strip_tags use a whitelist for skip some tags that you don't want were get rid. Anybody knows some implementation but using a blacklist instead of a whitelist? A simple compound regex search would work (if this is still about your previous issue): $html = preg_replace("#</?(font|strike|marquee|blink|del)[^>]*>#i", "", $html); Try this function posted by LWC on php.net - http://www.php.net/manual/en/function.strip-tags.php#96483 <?php function strip_only($str, $tags, $stripContent = false) { $content = ''; if(!is_array($tags)) { $tags = (strpos($str, '>') !== false ? explode('>', str

strip_tags enough to remove HTML from string?

て烟熏妆下的殇ゞ 提交于 2019-12-02 04:22:29
The site user can sign-up on a site, and during sign-up he can provide a name. I want this name to be a valid name, and free of any HTML and other funky characters. Is strip_tags enough for this? I find that there's no single function for idiot-proofing user inputs. Best to mix a few together: $val = trim($val); $val = strip_tags($val); $val = htmlentities($val, ENT_QUOTES, 'UTF-8'); // convert funky chars to html entities $pat = array("\r\n", "\n\r", "\n", "\r"); // remove returns $val = str_replace($pat, '', $val); $pat = array('/^\s+/', '/\s{2,}/', '/\s+\$/'); // remove multiple whitespaces

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

 ̄綄美尐妖づ 提交于 2019-12-01 16:54:29
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 for is a clever way to parse HTML in order to get rid only actual HTML tags. Since TinyMCE was used