Re: explode string variable

From: Date: Sat, 08 Mar 2003 16:00:39 +0000
Subject: Re: explode string variable
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-26195@lists.php.net to get a copy of this message
sannerholt@freenet.de (André Sannerholt) writes: > Does anybody know how to "stop" an "explosion" of a string: Let me explain: > > $variable_aray=explode('-', $variable); > > I want the variable to be devided in only two other ones! If for example: > > $variable="Willy-Brandt-Platz-5" > > I want to have an array that looks like this: > > $variable_array[0] should be "Willy" > $variable_array[1] should be "Brandt-Platz" I guess you could use the "proper" regexp functions, like e.g. preg_match("/^(\w+)-(.*?)-\d/", $variable, $matches) then $matches[1] and $matches[2] should (haven't tested) contain what you want... -- --Fredrik My opinions may have changed, but not the fact that I am right.

« previous php.db (#26195) next »