Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

return first full sentence of a string?

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

return first full sentence of a string?

Postby don.steele2 » Mon Feb 10, 2003 8:00 am

I am looking for a function or script that can return just the first full sentence (i.e. start of string until the first period) of a string that has several paragraphs. Essentially, this is to emulate news websites, wherein the story title, and the fist line of the story text is displayed. Thanks!
don.steele2
New php-forum User
New php-forum User
 
Posts: 2
Joined: Mon Feb 10, 2003 7:26 am

Postby flash_harry » Mon Feb 10, 2003 8:14 am

Well I'm kinda new to the whole php thing but i might be able to help a wee bit and if it is no help sure i've lost nothin.

To get a sentence out I might try using strtok() with a delimiter of "."

somethin like

$test = "hello, my name is Joe. I am 20";
$delimiter = ".";
$sentence = strtok($test, $delimiter);
print $sentence;

for me this outputted "hello, my name is Joe"
flash_harry
New php-forum User
New php-forum User
 
Posts: 26
Joined: Thu Jan 16, 2003 6:05 am

"I work in a button factory"

Postby don.steele2 » Mon Feb 10, 2003 8:24 am

Harry,
Perfect, that was exactly, what I was looking for. Thanks!
don.steele2
New php-forum User
New php-forum User
 
Posts: 2
Joined: Mon Feb 10, 2003 7:26 am


Return to PHP coding => General

Who is online

Users browsing this forum: Bing [Bot] and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.