PHP strip tags also removing \n
I'm using strip_tags in PHP and after it has processed the string, the string n开发者_Go百科ow also contains no \n's..
Is this standard with strip_tags?
Well, is it so hard to test? :)
class StripTagsTest extends PHPUnit_Framework_TestCase {
public function testStripTagsShouldNotRemoveLF() {
$input = "Hello\n <b>World</b>\n";
$actual = strip_tags($input);
$expected = "Hello\n World\n";
$this->assertEquals($expected, $actual);
}
public function testStripTagsRemovesBRTagByDefault() {
$expected = "HelloWorld\n";
$input = "Hello<br>World<br>\n";
$actual = strip_tags($input);
$this->assertEquals($expected, $actual);
$input = "Hello</br>World</br>\n";
$actual = strip_tags($input);
$this->assertEquals($expected, $actual);
}
public function testStripTagsCanPermitBRTags() {
$expected = "Hello<br>World<br>\n";
$actual = strip_tags($expected, '<br>');
$this->assertEquals($expected, $actual);
$expected = "Hello</br>World</br>\n";
$actual = strip_tags($expected, '<br>');
$this->assertEquals($expected, $actual);
}
}
This test will pass. The same result is while using single quotes. So, no, strip_tags doesn't remove \n.
EDIT:
Just as already other people here pointed out - strip_tags probably removes <br>
tag in your case. Also, next time, if you provide some code, you will get your answer quicker.
Added two new tests :)
Strip_tags should not remove \n but maybe it removes <br>
.
Try adding a list of tags to permit:
strip_tags('Hello<br>World', '<br>');
this shold allow <br>
tags to stay in the string.
精彩评论