I'm using strip_tags in PHP and after it has processed the string, the string now also contains no \n's..
Is this standard with strip_tags?
I'm using strip_tags in PHP and after it has processed the string, the string now also contains no \n's..
Is this standard with strip_tags?
The purpose of stripcslashes is to remove \n \r etc as indicated here.
http://www.php.net/manual/en/function.stripcslashes.php
Is there anything else in your code you can provide?
A test with a simple:
$str = "This is a test \n \n \n \n where are you going?";
echo strip_tags($str);
// still will print out the first sentence followed by four lines then the second sentence
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.
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 :)