Re: Dividing, and keeping, text from the first space

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On Aug 8, 2006, at 11:30 PM, Dave M G wrote:

PHP List,

This regular expression stuff is way tricky.

Thanks to help from this list, I have an expression that will select the first word of a string, up to the first white space:
"#^(.*)\s#iU"

But after some consideration, I realized that I wanted to keep both parts of the original text. The first word, and then everything that came after it, should be divided and stored in separate variables.

Now, I would do this different. Probably "wrong" but instead of a regular expression here, I would do something like this:

$array = explode(" ",$string);
$first_word = $array[0];
$rest_words = substr_replace($string,"",0,strlen($first_word));

--
Kevin Murphy
Webmaster: Information and Marketing Services
Western Nevada Community College
www.wncc.edu
775-445-3326


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux