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
https://forums.phpfreaks.com/topic/94785-cutting-the-text-short/
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; 
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.