Jump to content

Limit characters/words from database


Mutley

Recommended Posts

write a simple function for display purposes such as
[code]
<?php
function displayText($text)
{
  $addon = "...";
  $text1 = substr($text, 0, 11);
  $returntext = "$text1$addon";
  return $returntext;
}
?>
[/code]
$text = "Hello World how are you today?";

$newtext = displayText($text);

echo $newtext ;

would display          Hello World...

hope that helps
Note that this would also add the "..." to a value that already has less then say 15 characters.

Solution:

[code]
<?php
function displayText($text)
{
  $addon = "...";
  $text1 = substr($text, 0, 11);
  if($text <> $text1){
  $returntext = "$text1$addon";}else{$returntext = $text;}
  return $returntext;
}
?>
[/code]

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.