开发者

Are ampersands not allowed in php if-statements?

This is how my if-statement starts:

<?php if ( bbp_get_forum_title() == 'Business & Finance' ) : ?>

If I write just 'Business' it works as expected. But I now that I placed an ampers开发者_如何学JAVAand the statement doesn't work any more (the output is not being echoed).

Any suggestions to fix this?

EDIT:

This is the source code:

<li id="customwidget-3" class="widget-container widget_customwidget">             <h3 class="widget-title">Sponsored</h3>

Business &#038; Finance              
</li>

But if I check the code with firebug I get an &amp;.


it is possible that your title contains an HTML encoded ampersand entity (&amp;), rather than a plain ampersand character. This would be why it doesn't match, even though it looks correct when viewed in the browser.

To confirm this, try viewing the HTML source code for your title to see what the actual string is, rather than simply relying on how it looks in the browser.

Hope that helps.


if

<?php if ( bbp_get_forum_title() == 'Business & Finance' ) : ?>

Doesn't work try:

<?php if ( bbp_get_forum_title() == 'Business &amp; Finance' ) : ?>

if that doesn't work try:

<?php if ( bbp_get_forum_title() == 'Business &#038; Finance' ) : ?>


Inside a string, like in your example, ampersands are allowed in php if statements. The error is elsewhere.

As others pointed, probably &amp; is not matching & and that's why the result is different from what you expected.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜