CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2001
    Location
    Belgrade, Serbia
    Posts
    629

    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

  2. #2
    You could use the substr function. Ideally, you would add the ... only if the length were less than the maximum.
    Software Top Ten List: www.basepath.com/topten

  3. #3
    Join Date
    Mar 2001
    Location
    Belgrade, Serbia
    Posts
    629
    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
  •  





Click Here to Expand Forum to Full Width

Featured