How can I put sentences into an array?

Discussion in 'PHP' started by mcrae44, Dec 15, 2007.

  1. #1
    Hello everyone, I'm really new to php, here is what I want to do.

    Search through a body of text, untill it reaches "." "!" or "?" followed by single or double quotes, or a space. then put all text its gone through so far into the first array element. Then start over from that position.

    I was trying to do it like this: $url = explode("[.|/?|!] ", $_REQUEST["text"]);
    but it wasn't working, I can only get it to work for a single punctuation, and then the data in the arrays doesn't have punctuation, which is a bad thing. Can anyone help please?

    edit: the final purpose of the script is to display the shortest 5 and longest 5 sentences in the text, if that matters at all :)
     
    mcrae44, Dec 15, 2007 IP
  2. streety

    streety Peon

    Messages:
    321
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #2
    It looks like you may need regex

    $regex = '/(.+[\.!\?])\s/s';
    $sentances = preg_split($regex, $text);
    var_dump($sentances);
    
    PHP:
     
    streety, Dec 15, 2007 IP
  3. MMJ

    MMJ Guest

    Messages:
    460
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Nice one streety. :)
     
    MMJ, Dec 15, 2007 IP