During the first interview, the interviewer asked me if the tags in the string were not closed,what would strip_tags do with them?
The strip_tags is described in the official PHP document as follows;
strip_tags - Remove HTML and PHP tags from the string
Note the warning below the document:
because strip_tags () cannot actually validate HTML, incomplete or broken labels will result in more data being deleted.
What do you mean by this sentence?
Here are a few examples to show you
Sample1:
$testStr 1 = "<strong>hello world!</strong>"; Echo strip_tags ($testStr 1);
Output:
Hello world!
Sample2:
$testStr 1 = "<strong>hello world!"; Echo strip_tags ($testStr 1);
Output:
Hello world!
Sample3:
$testStr 2 = "<stronghello world!</strong>"; Echo strip_tags ($testStr 2);
Output empty string
Sample4:
$testStr 3 = "Hello World1<stronghello world2!</strong>hello world3"; Echo strip_tags ($testStr 3);
Output:
Hello World1
We can see from the above cases that the Strip_tags function clears all strings after an unclosed label when dealing with a label that is not closed.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
PHP function strip_tags label not closed case