php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #42864 strip_tags() doesn't work as expected with PHP tags
Submitted: 2007-10-05 10:37 UTC Modified: 2007-11-21 15:08 UTC
From: kraghuba at in dot ibm dot com Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: 5.2.4 OS: windows XP,linux
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: kraghuba at in dot ibm dot com
New email:
PHP Version: OS:

 

 [2007-10-05 10:37 UTC] kraghuba at in dot ibm dot com
Description:
------------
when a string with PHP tag(<?php ?>) is given as input to strip_tags() function, it strips off the entire given string including the tags. Whereas, the function should only strip the tags and not the text within the PHP block.

As per the documentation, this seems to be non-documented behavior, is this expected? 

Reproduce code:
---------------
<?php
var_dump(strip_tags("<?php echo \"hello\" ?>"));
?>

Expected result:
----------------
string(12) "echo "hello""

Actual result:
--------------
string(0) ""

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-10-05 10:39 UTC] kraghuba at in dot ibm dot com
This behavior is found on php6 as well.
 [2007-10-06 00:00 UTC] jani@php.net
According to the sources this is expected behaviour.
And it's pretty simple, <?php $foo=1; ?> is just another tag. So it's stripped as would something like <img src="foo.gif" /> be sripped..

 [2007-10-08 11:01 UTC] rquadling@php.net
What is missing though is a way to preserve the PHP "tag".

Just as HTML comments are always removed, PHP code will be also.

Both the HTML comments and PHP "tags" fail to match the usual formats of HTML tags ...

<tag></tag> or <tag />

So

<!-- xxxx -->
<?php xxxx ?>

are not capable of being described for allowable_tags.


 [2007-11-21 15:08 UTC] vrana@php.net
strip_tags() works exactly as documented: "This function tries to return a string with all HTML and PHP tags stripped".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 09:01:27 2024 UTC