0

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

3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by pushpakalpana
0

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";
}
0

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 (......)

Edited by muralikalpana: n/a

0

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";
}
}

Edited by mike_2000_17: Fixed formatting

1

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;
}

?>
Votes + Comments
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.