shaunno2007 Posted August 17, 2008 Share Posted August 17, 2008 This is about "substr". How can i make so that ... goes on the end of my string but only if it goes over the length? Link to comment https://forums.phpfreaks.com/topic/120021-solved-quotsubstrquot/ Share on other sites More sharing options...
Fadion Posted August 17, 2008 Share Posted August 17, 2008 <?php $str = 'this is some random text'; $maxlength = 10; if(strlen($str) > $maxlength){ echo substr($str, 0, $maxlength); } else{ echo $str; } ?> Link to comment https://forums.phpfreaks.com/topic/120021-solved-quotsubstrquot/#findComment-618271 Share on other sites More sharing options...
shaunno2007 Posted August 17, 2008 Author Share Posted August 17, 2008 how can i put it with this cos i have this... <?php while($website_row = mysql_fetch_array($website_result)) { ?> <a href="http://<?php echo $website_row['url']; ?>" target="_blank"><?php echo substr ($website_row['link'], 0, 76). "<br />" ; } ?></a> Link to comment https://forums.phpfreaks.com/topic/120021-solved-quotsubstrquot/#findComment-618292 Share on other sites More sharing options...
Fadion Posted August 17, 2008 Share Posted August 17, 2008 <?php while($website_row = mysql_fetch_array($website_result)){ ?> <a href="http://<?php echo $website_row['url']; ?>" target="_blank"> <?php if(strlen($website_row['link']) > 76){ echo substr($website_row['link'], 0, 76) . '<br />' ; } else{ echo $website_row['link']; } ?> </a> <?php } ?> Link to comment https://forums.phpfreaks.com/topic/120021-solved-quotsubstrquot/#findComment-618294 Share on other sites More sharing options...
shaunno2007 Posted August 17, 2008 Author Share Posted August 17, 2008 thanks works great Link to comment https://forums.phpfreaks.com/topic/120021-solved-quotsubstrquot/#findComment-618331 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.