Re: simple Regex
| From: | Cynic | Date: | Thu, 07 Dec 2000 11:58:23 +0000 |
| Subject: | Re: simple Regex | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-29104@lists.php.net to get a copy of this message | ||
Or you can use this:
function npos( $haystack , $needle , $occurrence )
{
if( $occurrence > substr_count( $haystack , $needle ) ) {
return false ;
} ;
for( $i = 0 , $offset = -1 ; $i < $occurrence ; $i++ ) {
$offset = strpos( $haystack , $needle , $offset + 1 ) ;
} ;
return $offset ;
}
$words = 'Via Monticano Del COLLE' ;
$first_three_words = substr( $words , 0 , npos( $words , ' ' , 3 ) ) ;
At 13:55 7.12. 2000, php3@developersdesk.com wrote the following:
--------------------------------------------------------------
>Addressed to: delbono@dsc.it (Delbono)
> php-general@lists.php.net
>
>** Reply to note from delbono@dsc.it (Delbono) Thu, 7 Dec 2000 11:52:11 +0100
>>
>> Hello.
>>
>> I've this string to parse: Via Monticano Del COLLE
>>
>> How can I get the first three words?
>
>
>$Words = explode( ' ', $String );
>
>$FirstThree = implode( ' ', array( $Words[0], $Words[1], $Words[2] ));
>
>
>
>I bet it is faster than ereg...
>
>
>
>
>
>Rick Widmer
>Internet Marketing Specialists
>http://www.developersdesk.com
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
>For additional commands, e-mail: php-general-help@lists.php.net
>To contact the list administrators, e-mail: php-list-admin@lists.php.net
------end of quote------
____________________________________________________________
Cynic:
A member of a group of ancient Greek philosophers who taught
that virtue constitutes happiness and that self control is
the essential part of virtue.
cynic@mail.cz
ICQ: 2808 2505