[PHP-DB] Re: explode string variable

2003-03-08 Thread Joel Colombo
or just :

$word = "James-Martin-Smith"
$word_break = Array();
$first_dash = strpos($word, '-');
if ($first_dash !== false) {
$word_break[0] = substr($word,0,$first_dash+1);
$word_break[1] = substr($word,$first_dash+1,strlen($word));
}







"André Sannerholt" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hi everyone!
>
> 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"
>
>
> Regards
>
> André
>
>
>



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



[PHP-DB] Re: explode string variable

2003-03-08 Thread Fredrik de Vibe
[EMAIL PROTECTED] (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.

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