php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #66299 General sugestion on the correct use function strip_tags
Submitted: 2013-12-16 01:19 UTC Modified: 2021-09-23 16:27 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: m dot klemarczyk at live dot com Assigned: cmb (profile)
Status: Closed Package: Strings related
PHP Version: 5.5.7 OS:
Private report: No CVE-ID: None
 [2013-12-16 01:19 UTC] m dot klemarczyk at live dot com
Description:
------------
---
From manual page: http://www.php.net/function.strip-tags
---

I'm not opposed to the current way of using this function.
I think that should also behave similarly to how JS interprets tags. This functionality can be for many people a very useful, for one simple reason, passed all structures specified tag.

Test script:
---------------
<?php // striptags.php 
$data = '<br>Each<br/>New<br />Line'; 
$new  = strip_tags($data, '<br>'); 
var_dump($new);
$data = '<br>Each<br/>New<br />Line'; 
$new  = strip_tags($data, '<br/>'); 
var_dump($new);
$data = '<br>Each<br/>New<br />Line'; 
$new  = strip_tags($data, '<br />'); 
var_dump($new);
$data = '<br>Each<br/>New<br />Line'; 
$new  = strip_tags($data, array('br')); 
var_dump($new);
$data = '<br>Each<br/>New<br />Line'; 
$new  = strip_tags($data, array('BR')); 
var_dump($new);
?>

Expected result:
----------------
// OUTPUTS string(21) "<br>EachNew<br />Line"
// OUTPUTS string(16) "Each<br/>NewLine"
// OUTPUTS string(11) "EachNewLine"
// OUTPUTS string(21) "<br>Each<br/>New<br />Line"
// OUTPUTS string(21) "<br>Each<br/>New<br />Line"

Actual result:
--------------
// OUTPUTS string(21) "<br>EachNew<br />Line"
// OUTPUTS string(16) "Each<br/>NewLine"
// OUTPUTS string(11) "EachNewLine"
// OUTPUTS string(11) "EachNewLine"
// OUTPUTS string(11) "EachNewLine"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-09-23 16:27 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2021-09-23 16:27 UTC] cmb@php.net
$allowed_tags may be an array as of PHP 7.4.0.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 05:01:29 2024 UTC