PDA

View Full Version : limit number of characters


error_22
03-30-2006, 06:48 PM
I want to limit the numbers of characters, but i dont know how to do that. Can someone help me?


if ($show == "ad"){
$sql = "SELECT * FROM ads Where id='".$_GET[id]."'";
$result = mysql_query($sql) or die("SQL: $sql ".mysql_error());
while ($adsresult = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo "$adsresult[fname] $adsresult[lname] <br>
<b>E-post:</b> $adsresult[email] <br>
<b>Kategori:</b> $adsresult[category] <br>
<b>Rubrik:</b> $adsresult[head] <br>
<b>Meddelande:</b> $adsresult[message] <br>
<b>Datum:</b> $adsresult[date] <br>";
}}
I want to limit the numbers of characters in just "$adsresult[message]" and also add "..." after, is that possible?

Thanks in advance
Niklas

Princeton
03-30-2006, 09:30 PM
try: fetch_trimmed_title($text, $limit)

sabret00the
03-30-2006, 09:49 PM
alternatively www.php.net/substr

error_22
04-02-2006, 01:37 PM
Thanks a lot for replying!

Im experiencing a problem though;

If I use...

echo substr('abcdef', 0, 4); // abcd

...It works, but not if I replace "abcdef" with "$adsresult[message]" i just get:

"$ads"

Im assuming it simply prints parts of the variable, what do I ned to change so it actually prints the content of the variable?

Thanks so much
Niklas

EDIT: nvm, it works now, thanks a lot for helping!

Code Monkey
04-02-2006, 02:50 PM
Don't put quotes aroud the variable and it should be $adsresult['message'].