开发者

php split string

in php I want to split the following value by using @$

$v开发者_运维问答al = "test1@$test";

But using explode it can't.any solutions?


It will if you escape the $ sign in double quotes. Or alternatively use single quotes to express the string.

Example:

$val = "test1@\$test";

or

$val = 'test1@$test';

If a dollar sign ($) is encountered, the parser will greedily take as many tokens as possible to form a valid variable name according to the manual.


$val = "test1@$test";
var_dump($val); // string(6) "test1@"

It's not the split() that's failing -- it's the assignment statement.


It is possible to explode to do this:

$val = 'test1@$test';
$array = explode('@$', $val);
print_r($array);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜