ohdang888 Posted January 1, 2008 Share Posted January 1, 2008 how do i say ........ if the number of characters in $example is greater than zero, then use this html code. if not, then skip the html code. ???????????????????????? Quote Link to comment https://forums.phpfreaks.com/topic/84014-solved-how-i-do-this/ Share on other sites More sharing options...
trq Posted January 1, 2008 Share Posted January 1, 2008 <?php if (strlen($example) > 0) { // do this. } ?> Quote Link to comment https://forums.phpfreaks.com/topic/84014-solved-how-i-do-this/#findComment-427523 Share on other sites More sharing options...
ohdang888 Posted January 2, 2008 Author Share Posted January 2, 2008 thanks, but one problem... its giving this error: Parse error: syntax error, unexpected '<' in C:\xampp\htdocs\game.php on line 61 heres my full code <?php $game_pic = stripslashes($row['game_picture_url']); if (strlen($game_pic) > 0) { <IMG SRC="gamepic/<?php echo stripslashes($row['game_picture_url'])?>" WIDTH="150" HEIGHT="110" BORDER="0" ALT= "free online (THIS IS LINE 61) games, free flash games"> } ?> Quote Link to comment https://forums.phpfreaks.com/topic/84014-solved-how-i-do-this/#findComment-427737 Share on other sites More sharing options...
interpim Posted January 2, 2008 Share Posted January 2, 2008 your mixing html and php without echoing it... rewrite your code to this <?php $game_pic = stripslashes($row['game_picture_url']); if (strlen($game_pic) > 0) { echo "<IMG SRC="gamepic/"; echo stripslashes($row['game_picture_url']). " ' WIDTH='150' HEIGHT='110' BORDER='0' ALT= 'free online (THIS IS LINE 61) games, free flash games">"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/84014-solved-how-i-do-this/#findComment-427783 Share on other sites More sharing options...
ohdang888 Posted January 2, 2008 Author Share Posted January 2, 2008 but taht s giving me this: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in C:\xampp\htdocs\game.php on line 66 whats wrogn??? ah. Quote Link to comment https://forums.phpfreaks.com/topic/84014-solved-how-i-do-this/#findComment-427797 Share on other sites More sharing options...
chronister Posted January 2, 2008 Share Posted January 2, 2008 <?php $game_pic = stripslashes($row['game_picture_url']); if (strlen($game_pic) > 0) { ?> <IMG SRC="gamepic/<?=stripslashes($row['game_picture_url']) ?>" WIDTH="150" HEIGHT="110" BORDER="0" ALT= "free online games, free flash games"> <?php } ?> Try that... the single and double quotes were being mixed and not escaped properly. Quote Link to comment https://forums.phpfreaks.com/topic/84014-solved-how-i-do-this/#findComment-427820 Share on other sites More sharing options...
ohdang888 Posted January 2, 2008 Author Share Posted January 2, 2008 it works! thanks! Quote Link to comment https://forums.phpfreaks.com/topic/84014-solved-how-i-do-this/#findComment-427823 Share on other sites More sharing options...
chronister Posted January 3, 2008 Share Posted January 3, 2008 Notice how I dropped out of PHP and into HTML and back when needed. This can sometimes make the code a bit sloppy, but it allows you to avoid a lot of single and double quotes and escaping them properly and such. I always try to use ' ' when possible. for example.. <?php $var1='<a href="#" class="someclass">This is my string when I need to </a>escape for a '.$variable .' I do so like that see '.$anothervar; ?> Notice how I did not have to escape the hell out of the HTML. It helps in the long run. Hope I helped some. Nate Quote Link to comment https://forums.phpfreaks.com/topic/84014-solved-how-i-do-this/#findComment-429075 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.