jesushax Posted June 16, 2008 Share Posted June 16, 2008 hi below is my code what i want to do is not write the last work if the total characters are going to be greater that 40 <?php $title = $port["ClientCompany"].' - '.$port["ProjectTitle"]; echo substr($title,0,40); ?> Quote Link to comment Share on other sites More sharing options...
webent Posted June 16, 2008 Share Posted June 16, 2008 maybe something like... $titleLength=strlen($title); if ($titleLength > 40) { substr($title,0,40); // Or do whatever you want to the string if it is longer // Maybe even something like this to replace a word if it is longer... $search = array("'"); $replace = array(""); $fields = str_replace($search,$replace,$fields); } Quote Link to comment Share on other sites More sharing options...
rhodesa Posted June 16, 2008 Share Posted June 16, 2008 How about this? <?php $title = substr($title,0,41); $title = substr($title,0,strrpos($title,' ')); print $title; ?> Quote Link to comment Share on other sites More sharing options...
webent Posted June 16, 2008 Share Posted June 16, 2008 Yes, LOL... rhodesa's code is much cleaner... I'm notorious for not combining built in functions... Quote Link to comment Share on other sites More sharing options...
jesushax Posted June 16, 2008 Author Share Posted June 16, 2008 thanks works a treat Quote Link to comment 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.