everyone, I'm sure this is a feature and not a bug, and I'm overlooking something obvious here. But I just can't see it.
I have the following code, which consists of HTML, peppered with some PHP stuff wrapped in short tags:
$wtf = <<<WTF开发者_运维百科
<h1>First header</h1>
<p class="intro">First line of text</p>
<h2>Second header</h2>
<p>Second line of text</p>
<?= showImg ('image.jpg'); ?>
<p>Third line of text</p>
<?= showImg ('image.jpg', ''); ?>
<p>Fourth line of text</p>
<?= showImg ('image.jpg', '', ''); ?>
<p>Fifth line of text</p>
<?= showImg ('image.jpg', '', 'class="content"'); ?>
<p>Sixth line of text</p>
WTF;
echo strip_tags ($wtf);[/CODE]
This outputs the following:
First header
First line of text
Second header
Second line of text
Third line of text
Fourth line of text
Fifth line of text[/CODE]
As you can see the sixth line of text is not included in the output. The culprit is the preceding line,
<?= showImg ('image.jpg', '', 'class="content"'); ?>
or rather, the third parameter in the showImg() call. As soon as strip_tags() encounters this part, it simply quits without displaying an error message and returns the text processed so far - which leads me to believe that somehow it believes having encountered the end of the data that it's supposed to process.
Why?
Incidentally, the bit itself works fine when I run it, and even with full error reporting generates no syntax-related warnings or errors, so I believe it's valid and allowable syntax. Yes, I am aware of the whole semi-religious discussion on whether or not using short tags are a good idea, but right now I am using it and all I want to know is why strip_tags returns prematurely when it encounters that third parameter in the showImg() call.
Google, other forums and a search on StackOverflow have not resulted in enlightenment. Can anyone tell me what's going on here? Thanks - it would be greatly appreciated!
// Frank
The problem is not related to the heredoc syntax; I've merely used that in this example. The problem is with the string data fed into strip_tags, which occurs regardless of how the data is obtained - returned from a function, assigned to a variable using the usual $string="fubar" syntax, or whatever.
精彩评论