Re: Dividing, and keeping, text from the first space
| From: | Kevin Murphy | Date: | Wed, 09 Aug 2006 15:11:07 +0000 |
| Subject: | Re: Dividing, and keeping, text from the first space | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-240378@lists.php.net to get a copy of this message | ||
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