hello.....
i am fetching text from database. i want to restrict 400 characters from that after "readmore". it redirects to total page.

i was used substring but i want to total validate what means after 400 characters there is '.' is there then not appear '.........'like this. otherwise appear after word '............' .
how to do plz...........sugest me

Think this is it, just apply your db info to teh $db_text variable;

$db_text = $db_info[text];

echo substr($db_text, 0, 400);
if(strlen($db_text) > 400){
echo "........ Read More";
}

Think this is it, just apply your db info to teh $db_text variable;

$db_text = $db_info[text];

echo substr($db_text, 0, 400);
if(strlen($db_text) > 400){
echo "........ Read More";
}

yes i tried same like this. but what i am saying means for suppose after 400characters there is (.) or there is (,)then how to restrict that (......)

I think I see what you mean.

$db_text = $db_info[text];
$last_char = strlen($db_text)-1;

echo substr($db_text, 0, 400);
if(strlen($db_text) > 400){
if($last_char == "." || $last_char == ","){
  //last char is . or ,
}else{
   //last char is something else.
   echo "........ Read More";
}
}

hello.....
i am fetching text from database. i want to restrict 400 characters from that after "readmore". it redirects to total page.

i was used substring but i want to total validate what means after 400 characters there is '.' is there then not appear '.........'like this. otherwise appear after word '............' .
how to do plz...........sugest me

try this.

<?php

$long_text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
$max_length = 40; // we want to show only 40 characters.

if (strlen($long_text) > $max_length)
{
 $short_text = (substr($long_text,0,$max_length-1)); // make it $max_length chars long
 $short_text .= "..."; // add an ellipses ... at the end
 $short_text .= "<a href='http://example.com/page.html'>Read more</a>"; // add a link
 echo $short_text;
}
else
{
// string is already less than $max_length, so display the string as is
echo $long_text;
}

?>
commented: nice +1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.