RE: Formatting an ECHO statement.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I ask as you look at the comments and replies to your post, you think long
term. 
Today you want the italic option, tomorrow you want to change the display to
something else.  Now you have to go back and change ever place you set the
italic symbols to make your change. 

BUT if you use styles you can not only change the display to the desired
look in one location but you can have flexibility.

Example:

Let's say the comments are coming from a database and you want to display
the comment differently based on the contents of the comment.

In my example I have 3 different classes in the style. Now as I foreach over
the fake data array example, I simply pick the style to use based on each
matching criteria. While the static examples

<style>
#wever_comment{font-style:italic}
#good_comment{font-style:italic; color: green;}
#bad_comment{font-weight:bold; color: red;}
</style>

$variable_from_database = array('good','bad','whatever');
Foreach($variable as $key)
{
	Echo 'Other Comments:';
	If(preg_match("/bad/i",'$key')){Echo '<div
class=bad_comment>$key</div>';}
	If(preg_match("/good/i",'$key')){Echo '<div
class=good_comment>$key</div>';}	
	If(preg_match("/whatever/i",'$key')){Echo '<div
class=wever_comment>$key</div>';}
	Echo '<br/>';
}

In the long term the flexibility allows you to make faster changes with a
higher degree, of what I like to call "smarter code". Yes the filters are
static, and I would not use static filters personally. It is meant as an
explanation, not a how to.











-----Original Message-----
From: Shreyas Agasthya [mailto:shreyasbr@xxxxxxxxx] 
Sent: Monday, October 18, 2010 6:10 AM
To: PHP General List
Subject:  Formatting an ECHO statement.

Team,

A bit of silly one but like my book says, there are no dumb questions, I am
asking it here.

If I have :

$other="Whatever";

and I do:

echo 'Other Comments:' .$other. '<br/>

works perfectly well and prints the value. What if I want to, now, italicize
the value of $other with the above syntax? How do I achieve it?

I know we can do it this way : echo " I am <i>$other</i>"; but I want to
learn how to do it with the above syntax like I mentioned earlier.

Regards,
Shreyas Agasthya


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux