|
-
May 24th, 2002, 03:36 AM
#1
parsing string in PHP
hi all,
how can I 'cut off' string in PHP?
for example:
I have a field in dbase smth TEXT , and fill it with some text... like "This is a text, blah, blah" (of couse real text is much larger).
now, how can I create a "preview" of that so when I display result of query it shows only first few words: This is a ..... .
what i figured out is this:
PHP Code:
$strDisplay = $row[text];
$strParse = $strDisplay{0} . $strDisplay{1} . $strDisplay{2};
which is not an option.... I'd like, say, first 20 chars to be displayed...
but how can I do like in c++ : $strParse = $strDisplay.Left(20) to take first 20 chars from left.....
TIA,
boris
-
May 24th, 2002, 02:02 PM
#2
You could use the substr function. Ideally, you would add the ... only if the length were less than the maximum.
-
May 24th, 2002, 03:06 PM
#3
yes, i tried
PHP Code:
$strDisplay = $row[text];
$strParse = substr($strDisplay,0,250) . "...";
...and it works like charm....
thx a lot
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|