#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    4
    Rep Power
    0
    I have been looking through some of my PHP books and through this forum.

    I have determined that I can chop off my body for use as a document summary using the $body=substr($body, 0, 150) function.

    My question is...

    What can I add to have the summary cutoff at the nearest period?

    Example of bad solution:

    "Joe Schmo, the director of city development, announced his plans on what the city plans to do abo"

    Example of what I would like to do:

    "Joe Schmo, the director of city development, announced his plans on what the city plans to do about pollution in the new waterway."


    How can I go about setting the string to be cutoff at a "."(period)

  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    you can do that,if you don't want get cutoff after a certain length then try this..

    <?
    $variable="Joe Schmo, the director of city development, announced his plans on what the city plans to do abo";

    $values=explode(",",$variable);
    //seperate the string based on comma and put it in $values array.

    echo "summary : $values[0]";
    //print the first portion...
    ?>

    Good Luck!!


    ------------------
    SR -
    webshiju.com
    www.jobxyz.com-IT Career Portal
    ezipindia.com--WebStudio


    "The fear of the LORD is the beginning of knowledge..."

    [This message has been edited by Shiju Rajan (edited September 09, 2000).]
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Location
    Ontario, Canada
    Posts
    498
    Rep Power
    18
    You could also use strtok()...

    ex;
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    $string = "Hello there. What are you doing? I'm not doing anything.";
    $tok = strtok($string,".");
    echo $tok . "<br>";
    [/code]

    This will echo out "Hello there." (Or, at least it should. )

    ------------------
    To alcohol! The cause of, and solution to, all of life's problems. -- Homer Simpson

Similar Threads

  1. help with tables and wordwrapping
    By junkedBrian613 in forum PHP Development
    Replies: 2
    Last Post: February 15th, 2004, 06:42 PM
  2. Wan to select partial text in a text field
    By raghava66 in forum HTML Programming
    Replies: 2
    Last Post: February 12th, 2004, 03:11 AM
  3. how to keep table on top, not centered??
    By vinyl in forum HTML Programming
    Replies: 2
    Last Post: January 20th, 2004, 07:19 PM
  4. float question
    By yeah-yeah in forum HTML Programming
    Replies: 10
    Last Post: January 15th, 2004, 04:59 PM
  5. put variable in text field
    By alexmasters in forum PHP Development
    Replies: 3
    Last Post: January 14th, 2004, 08:32 PM

IMN logo majestic logo threadwatch logo seochat tools logo