wright67uk Posted October 11, 2012 Share Posted October 11, 2012 What would be the best way to display text and change its style based on a condition? Eg. If condition is true then display p.class as bold, if condition is false the display the p class in italic. Quote Link to comment https://forums.phpfreaks.com/topic/269339-how-do-i-change-p-class-based-on-a-condition/ Share on other sites More sharing options...
DarkerAngel Posted October 11, 2012 Share Posted October 11, 2012 (edited) 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"; ?> Edited October 11, 2012 by DarkerAngel Quote Link to comment https://forums.phpfreaks.com/topic/269339-how-do-i-change-p-class-based-on-a-condition/#findComment-1384446 Share on other sites More sharing options...
ManiacDan Posted October 11, 2012 Share Posted October 11, 2012 Note: some server's don't have "<?=" enabled"Short tags" are deprecated and shouldn't be used, they'll be out of the language entirely soon. Quote Link to comment https://forums.phpfreaks.com/topic/269339-how-do-i-change-p-class-based-on-a-condition/#findComment-1384503 Share on other sites More sharing options...
premiso Posted October 11, 2012 Share Posted October 11, 2012 (edited) "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. Edited October 11, 2012 by premiso Quote Link to comment https://forums.phpfreaks.com/topic/269339-how-do-i-change-p-class-based-on-a-condition/#findComment-1384530 Share on other sites More sharing options...
ManiacDan Posted October 11, 2012 Share Posted October 11, 2012 You're right, it was marked for permanent deletion and then they changed their mind. With that amount of back and forth I don't trust them for it, but as of this writing they're "always available" Quote Link to comment https://forums.phpfreaks.com/topic/269339-how-do-i-change-p-class-based-on-a-condition/#findComment-1384534 Share on other sites More sharing options...
premiso Posted October 11, 2012 Share Posted October 11, 2012 With that amount of back and forth I don't trust them for it Yea, who knows. Maybe PHP6 will remove it HAHAHAHAA Quote Link to comment https://forums.phpfreaks.com/topic/269339-how-do-i-change-p-class-based-on-a-condition/#findComment-1384536 Share on other sites More sharing options...
trq Posted October 11, 2012 Share Posted October 11, 2012 You're right, it was marked for permanent deletion and then they changed their mind. With that amount of back and forth I don't trust them for it, but as of this writing they're "always available" They were never marked for removal. Quote Link to comment https://forums.phpfreaks.com/topic/269339-how-do-i-change-p-class-based-on-a-condition/#findComment-1384650 Share on other sites More sharing options...
ManiacDan Posted October 12, 2012 Share Posted October 12, 2012 "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. Quote Link to comment https://forums.phpfreaks.com/topic/269339-how-do-i-change-p-class-based-on-a-condition/#findComment-1384747 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.