Jump to content

How Do I Change P Class Based On A Condition?


wright67uk

Recommended Posts

I'm a big fan of these:

 

HTML (Inline PHP)

<p>I'm a normal text</p>
<p class="<?=($bold)?"bold":"italic"?>">I should be bold or italic based on a PHP Variable!!!</p>

Note: some server's don't have "<?=" enabled this is simply "<?php echo" so the long version would be:

<?php echo ($bold)?"bold":"italic"; ?>

"Short tags" are deprecated and shouldn't be used, they'll be out of the language entirely soon.

 

You may want to check your facts on that :)

 

http://www.php.net/manual/en/ini.core.php#ini.short-open-tag

 

This directive also affected the shorthand <?= before PHP 5.4.0, which is identical to <? echo. Use of this shortcut required short_open_tag to be on. Since PHP 5.4.0, <?= is always available

 

What I think has been depreciated from the short tags, to my knowledge, is the opening <? which should be depreciated. I tend to use the <?= for .phtml type template files.

"Short tags" were marked for removal in PHP6, but that "official" decision is nowhere to be found in their changelogs.

 

Googling for it produces many articles like this one reporting on the short tag removal (which applied to both <? ?> and <?=$var?>).

 

As far as I can tell:

 

Short tags and short tag echoes were considered the same thing, and controlled by an ini setting.

 

They were deprecated briefly in the spring 2009.

 

That decision was reversed in the summer of 2009 (and I didn't notice).

 

PHP 5.4 split short tags and short echoes into two separate features, and turned short echoes on regardless of short tag settings.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.