English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I'm making a search form for my site. It searches a column named 'description'. I was wondering if on the search results page you can limit the number of characters for that field of results. Kinda like on other search engines it will give you a description of what items it found with a "..." after so many characters. How do you do this?

2006-09-30 00:25:09 · 3 answers · asked by detroitkid17 2 in Computers & Internet Programming & Design

3 answers

if(strlen($myDescription) > 50) {
$showDescription = substr($myDescription,1,50) . "...";
} else {
$showDescription = $myDescription;
}
echo $showDescription;
?>

enjoy!

2006-09-30 02:55:47 · answer #1 · answered by fwiiw 4 · 1 0

Is this more a MySQL question? You mention column, I take it you mean a column in a table.

If so the the key is to use SELECT Blah WHERE input LIKE

See Link below for more detail

2006-09-30 07:30:25 · answer #2 · answered by teef_au 6 · 0 1

Use the substr() function:

http://www.php.net/substr

For example, to trim a string $str to 50 characters, you can do:

substr($str, 0, 50);

2006-10-02 14:50:29 · answer #3 · answered by NC 7 · 0 0

fedest.com, questions and answers