php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #71286 strip_tags should remove non-text chararcters as well
Submitted: 2016-01-05 15:42 UTC Modified: 2016-01-05 16:26 UTC
From: leesleefeng at 163 dot com Assigned:
Status: Not a bug Package: Strings related
PHP Version: 5.6.16 OS: All
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: leesleefeng at 163 dot com
New email:
PHP Version: OS:

 

 [2016-01-05 15:42 UTC] leesleefeng at 163 dot com
Description:
------------
strip_tags should remove non-text chararcters as well.

When using strip_tags to remove html and php tags, the purpose is to get plain text. Thus if the tags has codes but not text inside, like style tag and script tag, the codes should be removed as well, not noly the tags.




Test script:
---------------
$s = <<<html
<style type="text/css">
    body,h1,h2,h3,h4,h5,h6{padding:0;margin:0;}
</style>
<script>
window.onload = function(){
    console.log('document is ready');
}
</script>
<div>
walking through the green fields, 
sunshine in my eyes
</div>
html;

$text = strip_tags($s);
echo $text;


Expected result:
----------------
walking through the green fields, 
sunshine in my eyes

Actual result:
--------------
    body,h1,h2,h3,h4,h5,h6{padding:0;margin:0;}
window.onload = function(){
    console.log('document is ready');
}
walking through the green fields, 
sunshine in my eyes


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-01-05 16:26 UTC] tyrael@php.net
-Status: Open +Status: Not a bug
 [2016-01-05 16:26 UTC] tyrael@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

by that same logic any well-formed html or xml string should result in an empty string.
strip_tags() doesn't work like that, and you can see that from the second example of the official documentation: http://php.net/strip_tags#example-5473
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Thu Dec 12 06:01:24 2019 UTC