Re: [PHP] beginner: cut text after " "

2003-08-28 Thread David Otton
On Wed, 27 Aug 2003 21:30:25 -0700, you wrote:

>Want to remove the string after the first whitespace like:
>
>"here is a text what i have"
>to:
>"here"

I'd explode() the string into an array, and take the 0th element of the
array.

$s = 'here is a text what i have';
$a = explode (' ', $s);
echo ($a[0]);

If you want to match  /whitespace/ (tab, space, etc), replace explode() with
split() using the correct regular expression.

(Note: explode() takes a 3rd optional parameter, limit, if you want a
remainder string, too.)

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] beginner: cut text after " "

2003-08-28 Thread John W. Holmes
Andras Kende wrote:

Hello All,

I have a very simple question:

Want to remove the string after the first whitespace like:

"here is a text what i have"
to:
"here"
$word = substr($sentence,0,strpos($sentence,' '));

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals – www.phparch.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] beginner: cut text after " "

2003-08-28 Thread Andras Kende

Hello All,

I have a very simple question:

Want to remove the string after the first whitespace like:

"here is a text what i have"
to:
"here"


Thanks !!

Andras Kende

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php