Re: [PHP] Limit output of query field

2003-07-05 Thread Dan Anderson
Look up the function substr.  It will allow you to create a string of
the first 50 chars from your 400 char string.

-Dan

On Sat, 2003-07-05 at 09:58, [EMAIL PROTECTED] wrote:
 Hi there,
 
 Hope you can help me with the following:
 
 I have a query and i'm showing the output:
 
 echo $row-text;
 
 That goes o.k. but the text is 400 characters long and I only one to show the first 
 50 characters and at the end showing ... dot's..
 
 Help!
 
 Thank you very much!
 
 Frank
 
 
 __
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Limit output of query field

2003-07-05 Thread Audun Larsen
Try this: 

if(strlen($row-text)50) {
echo substr($row-text,0,47) . ...;
} else {
echo $row-text;
}

- Audun

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Saturday, July 05, 2003 3:59 PM
To: [EMAIL PROTECTED]
Subject: [PHP] Limit output of query field


Hi there,

Hope you can help me with the following:

I have a query and i'm showing the output:

echo $row-text;

That goes o.k. but the text is 400 characters long and I only one to
show the first 50 characters and at the end showing ... dot's..

Help!

Thank you very much!

Frank



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Limit output of query field

2003-07-05 Thread Marek Kilimajer
Make it with your sql query, it will be faster:
SELECT ..., IF(LENGTH(text)50, CONCAT(SUBSTRING(text,0,50),'...'), 
text) as text

[EMAIL PROTECTED] wrote:
Hi there,

Hope you can help me with the following:

I have a query and i'm showing the output:

echo $row-text;

That goes o.k. but the text is 400 characters long and I only one to show the first 50 characters and at the end showing ... dot's..

Help!

Thank you very much!

Frank




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Limit output of query field

2003-07-05 Thread Dan Anderson
 Make it with your sql query, it will be faster:
 SELECT ..., IF(LENGTH(text)50, CONCAT(SUBSTRING(text,0,50),'...'), 
 text) as text

I won't outright disagree, but warn fkessen to be careful.  There are
some scenarios in which that would not be faster.

-Dan


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Limit output of query field

2003-07-05 Thread Giz
This add a bit more functionality, in that it will adjust to the nearest end
of a word, and includes a 'more' link to the full text.  This also assumes
that the article may already only be 50 chars or less.

$maxsize = 50; // might be better as a DEFINE
$post = $row-text;
$post = (strlen($post)  $maxsize ) ? substr(substr($post,0,$maxsize-1), 0,
strrpos(substr($post,0,$maxsize-1),' '))a
href='your_url_to_full_text' more/a : $post; 


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Saturday, July 05, 2003 6:59 AM
To: [EMAIL PROTECTED]
Subject: [PHP] Limit output of query field

Hi there,

Hope you can help me with the following:

I have a query and i'm showing the output:

echo $row-text;

That goes o.k. but the text is 400 characters long and I only one to show
the first 50 characters and at the end showing ... dot's..

Help!

Thank you very much!

Frank




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php