Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Limit text to display


skyknight

Recommended Posts

Pass your variable to this function.

add this function to your functions library

<?php

/**
* Add this to your page:
* <?php
* include "shorten_a_text_string.php";
* echo ShortenText($text);
* ?>
* where $text is the text you want to shorten.
* 
* Example
* Test it using this in a PHP page:
* <?php
* include "shortentext.php";
* $text = "The rain in Spain falls mainly on the plain.";
* echo ShortenText($text);
* ?>
*/

function ShortenText($text) {

	// Change to the number of characters you want to display
	$chars = 50;

	$text = $text." ";
	$text = substr($text,0,$chars);
	$text = substr($text,0,strrpos($text,' '));
	$text = $text."...";

	return $text;

}

?>

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...