Re: preg_split problem

From: Date: Sat, 09 Nov 2002 18:11:58 +0000
Subject: Re: preg_split problem
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-123602@lists.php.net to get a copy of this message
At 17:58 09.11.2002, samug said: --------------------[snip]-------------------- >$text = "And what did I tell you?"; >list($one,$two,$three,$rest) = preg_split("/\s+/", $text); >print($rest); > >The result would be "I" and not "I tell you?" --------------------[snip]-------------------- Your regex splits the entire string, and since you have only a list of four elements, the fourth element happens to be the "I". If you want the rest in $rest, you need a thried parameter to preg_split telling it how many elements the resulting array should have: $text = "And what did I tell you?"; list($one,$two,$three,$rest) = preg_split("/\s+/", $text, 4); print($rest); will correctly output "I tell you?" -- >O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/

« previous php.general (#123602) next »