Jump to content

Cutting the text short...


evie001001

Recommended Posts

I am new to PHP to please bear with me!

 

I am displaying information from my database (bindings) on my page... in the form of text. Is there anyway I could cut the text short to display only a few characters? For example, i'd like the job descriptions in this page: http://impserver.bournemouth.ac.uk/~emoore/jobs.php to be cut short so that a user can click 'more' and navigate to a separate page with full descriptions.

 

Any ideas?

 

Thanks :)

 

Evie

Link to comment
Share on other sites

here is one more solution, its an old one of mine and code heavy but it gives flexibility to trim where you want and set a trimming spread before the break

 

<?php                   
$posttext = "Soon you will know just how easy it is to build unncessaarily long routines. Take a look at counting words and seperating at a space or a period. This routine works well based on the trimto length";
		$str_len = strlen($posttext);
		if ($str_len >= 75) {
		$str_len = trim(strlen($posttext));
		$trimto = 65; 
		$select = 8;  // eight characters either way to a break
		 $i = 0;
	      for ($i = 0; $i < $trimto+$select; $i++) {
		   $current_char = substr($posttext,$i,1);
			if ($current_char == " " ) {
				$cutlength = $i;
				} 
	  }
   $textout = (substr($posttext, $str_len= 0, $cutlength));
}
 echo $textout; 
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.