RE: [PHP] adding text to variables

From: Date: Tue, 17 Sep 2002 08:39:29 +0000
Subject: RE: [PHP] adding text to variables
Groups: php.general 
Request: Send a blank email to php-general+get-116607@lists.php.net to get a copy of this message
> -----Original Message----- > From: Jason [mailto:jason@trgideas.com] > Sent: 16 September 2002 20:44 > > > I'm using PHP, MySql, DreamweaverMX, and PHAkt 2. I want to > add a comma ( > , ) to the end of a variable, but only if it exists in the database. > (Meaning I don't want a comma with no variable.) I seem to > remember a format > that didn't use an if/else statement that looked something like: > <?php echo xxx( $variable, \,) ?> This may not be what you were thinking of exactly, but my usual approach to this is to use the ?: ternary operator thusly: echo isset($variable)?"$variable,":''; or, to omit empty strings and zero values also: echo empty($variable)?'':"$variable,"; Cheers! Mike --------------------------------------------------------------------- Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: m.ford@lmu.ac.uk Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211

« previous php.general (#116607) next »