givecard 442 ashutosh2 Y
ashutosh2 442你好吗?
如果我把这条线分开,结果是
Array
(
[0] => givecard
[1] => 442
[2] => ashutosh2
[3] => Y
[4] => hi
[5] => how
[6] => are
[7] => you
)但我想要这样
Array
(
[0] => givecard
[1] => 442
[2] => ashutosh2
[3] => Y
[4] => hi how are you
)在这里,你好,我想在变量中提取完整的一条消息。我怎样才能做到这一点
发布于 2010-12-27 07:49:59
编辑:
preg_split('/\s+/', "givecard 442 ashutosh2 Y hi how are you", 5);假设你有这样的功能:
function operate_on_string($string) {
$out = preg_split('/\s+/', $string);
# ...
return $out;
}传递字符串"givecard 442 ashutosh2 Y“,并在其末尾附加”嗨,你好“:
operate_on_string("givecard 442 ashutosh2 Y" . ' ' . "hi how are you");只需将第一个字符串传递给它,然后将其余字符串附加到输出:
array_merge(operate_on_string("givecard 442 ashutosh2 Y"), preg_split('/\s+/', "hi how are you"));发布于 2010-12-27 07:50:24
从您的问题来看,我想这是一个预先格式化的字符串。让我看看,你能用爆炸()吗?
$format = explode(" ", $data, 5);发布于 2010-12-27 07:51:44
嗯,有可能通过smt来分离值吗?例如:
givecard:442:ashutosh2:y:嗨,你好吗
然后引爆它:
https://stackoverflow.com/questions/4537235
复制相似问题