0

Hi I had a database and a column called "details" in it. I need to select data from that column and show only limited characters of it.

For eg:
Original : The quick lazy fox jumps over a lazy dog.
Display : The quick lazy ...

How can I do with php and mysql....
Please help me.
Thanks in advance
Rajeesh

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by rajeesh_rsn
0

Use substr function. Note, I also used strpos in the example to ensure that the last word isn't broken up.

<?php
$str="The quick lazy fox jumps over a lazy dog.";
$space=" ";
$sppos=strpos($str,$space,10);
$str=substr($str,0,$sppos);
$str.=" ...";
echo $str;
?>

Example without strpos:

<?php
$str="The quick lazy fox jumps over a lazy dog.";
$str=substr($str,0,14);
$str.=" ...";
echo $str;
?>
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.