mcrae Posted December 15, 2007 Share Posted December 15, 2007 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? The final purpose of the script is to display the shortest 5 and longest 5 sentences in the text, if that matters at all Link to comment https://forums.phpfreaks.com/topic/81791-how-can-i-put-sentences-into-an-array/ Share on other sites More sharing options...
Barand Posted December 15, 2007 Share Posted December 15, 2007 use split() instead of explode(). www.php.net/split You still lose the final punctuation but that won't affect your final purpose to find shortest and longest Link to comment https://forums.phpfreaks.com/topic/81791-how-can-i-put-sentences-into-an-array/#findComment-415551 Share on other sites More sharing options...
boo_lolly Posted December 15, 2007 Share Posted December 15, 2007 yeah to elaborate it'd be something like: <?php $sentences = split('[.|/?|!] ', $string); print '<pre>'; print_r($sentences); print '</pre>'; ?> Link to comment https://forums.phpfreaks.com/topic/81791-how-can-i-put-sentences-into-an-array/#findComment-415647 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.