es131245 Posted September 7, 2010 Share Posted September 7, 2010 is there any way I can use if selse statement in str???example:$body.='<table id="share"><tr><th>Icon</th><th>Name</th><th>Type</th><th>Size</th><th>Modified</th></tr>';if(isset($share_dirs)){foreach($share_dirs as $u) {$body.='<tr><td><img src="/source/share/dir.png" /></td><td>'; if(strlen($u)<25){$body.=$u;}else{$body.=substr($u,0,22).'...';} $body.='</td><td>Dir</td><td>-</td><td>'.date("F d Y H:i:s", filemtime($share_url.$u)).'</td></tr>';}}so can i do something like$body.='<tr><td><img src="/source/share/dir.png" /></td><td>'.(if(strlen($u)<25){$body.=$u;}else{$body.=substr($u,0,22).'...';}).$body.='</td><td>Dir</td><td>-</td><td>'.date("F d Y H:i:s",filemtime($share_url.$u)).'</td></tr>'; Link to comment Share on other sites More sharing options...
real_illusions Posted September 7, 2010 Share Posted September 7, 2010 Try it, see what happens. Link to comment Share on other sites More sharing options...
es131245 Posted September 7, 2010 Author Share Posted September 7, 2010 I do =)))))))))) Parse error: syntax error, unexpected T_IF in /usr/local/www/data/body/act/share.php on line 56but there should be a wayits just cant find it =)))))))) Link to comment Share on other sites More sharing options...
Ingolme Posted September 7, 2010 Share Posted September 7, 2010 You might be looking for the Conditional OperatorAlternatively, you could just use a normal if() statement, assign the result to a variable and then concatenate it to the string. Link to comment Share on other sites More sharing options...
wirehopper Posted September 7, 2010 Share Posted September 7, 2010 This should work:$body.='<tr><td><img src="/source/share/dir.png" /></td><td>'.((strlen($u)<25)?$u:substr($u,0,22).'...').'</td><td>Dir</td><td>-</td><td>'.date("F d Y H:i:s",filemtime($share_url.$u)).'</td></tr>'; Instead of $body.='something'.$body.='some more'; it's easier to read $body.='something'.'some more';Also, check out the heredoc notation:http://www.php.net/manual/en/language.type....syntax.heredocAnother way to shorten the string is to use substr_replace (http://us3.php.net/manual/en/function.substr-replace.php) <?php$sTest='Test String';echo substr_replace($sTest,' ...',5).PHP_EOL;echo substr_replace($sTest,' ...',15).PHP_EOL;?> Link to comment Share on other sites More sharing options...
es131245 Posted September 7, 2010 Author Share Posted September 7, 2010 thxgot it well =) Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.