开发者

Split into two variables?

开发者 https://www.devze.com 2023-02-05 04:35 出处:网络
Say I have the following: \"44-xkIolspO\" 开发者_JAVA百科I want to return 2 variables: $one = \"44\";

Say I have the following: "44-xkIolspO"

开发者_JAVA百科

I want to return 2 variables:

$one = "44";
$two = "xkIolspO";

What would be the best way to do this?


Try this:

list($one, $two) = split("-", "44-xkIolspO", 2);

list($one, $two) = explode("-", "44-xkIolspO", 2);


PHP has a function called preg_split() splits a string using a regular expression. This should do what you want.

Or explode() might be easier.

    $str = "44-xkIolspO";
    $parts = explode("-", $str);
    $one = $parts[0];
    $two = $parts[1];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号