tags:

views:

85

answers:

4

I know that it's not possible to style any given PHP but I do know that it is possible to style the output HTML that the PHP provides you with. I was wondering if there was any method available for me to use that would enable me to style the output from my IF ELSE statement.

if ($result != false) {
    print "Your entry has successfully been entered into the blog.";
}
+3  A: 

Just use HTML in your printed string. Nothing fancy needed.

if ($result != false) {
    print "<p class=\"success\">Your <strong>entry</strong> has <a href=\"http://example.com/\"&gt;successfully&lt;/a&gt; been entered into the blog. <img src=\"smileyface.png\" alt=\"Smiley face\" /></p>";
}
ceejayoz
Don’t link “successfully”; link “entry” instead.
Gumbo
@Gumbo I was just throwing in arbitrary tags without regard for context to demonstrate their usage.
ceejayoz
A: 

You need to print HTML then.

if ($result != false) {
  print "<b>Your entry has successfully been entered into the blog.</b>";
}

Or even

if ($result != false) {
  print "<div class='Style1'>Your entry has successfully been entered into the blog.</div>";
}
rlb.usa
+1  A: 

You mean this?

if ($result != false) {
 print "<span style='color:#ff0000'>Your entry has successfully been entered into the blog.</span>";
}
Sarfraz
Thanks for that quick reply!
ThatMacLad
@ThatMacLad: You are welcome ..............
Sarfraz
+1  A: 

What I like to do, just to make life simple, is to switch between HTML and PHP in my page. For example,

<?php if ($fooSuccess = true) {?>
<p><span style="color: green;">Success!</span></p>
<?php } else {?>
<p><span style="color: red;">Error!</span></p>
<?php } ?>
NightMICU
Also, please note that this would be within your page's body tag
NightMICU
So "simple" is extra lines and jarring switches between PHP and non-PHP? Nesting gets nasty here too.
ceejayoz
Personally, keeping the element where it will actually end up in the page is easier than having it in another file or at the top of the page, at least for this application. Also, you do not need to worry about escaping quotes and the like this way. I learned this trick from PHP Solutions by David Powers, it's just one way of doing it -- so I don't think that a negative rating was really appropriate here, but to each their own.
NightMICU
Upvoting not because I'm partial to this style, but because downvoting based on stylistic differences in a one-off script is petty and counterproductive.
Cory Petosky
@ceejayoz time to give up spaghetti code and learn to use templates ;)
Col. Shrapnel
@Col. Shrapnel That's way out of the scope of this question, though.
ceejayoz
@ceejayoz your note - yes. But example itself is way better than ugly echoes from other answers.
Col. Shrapnel