开发者

how to transform a string to an array with # as a delimiter but only the first one?

开发者 https://www.devze.com 2022-12-14 17:45 出处:网络
(only the first # is a delimiter) 50#some message from me to you #1 or #2 into array ( [amount] => 50 [message] =>开发者_JS百科 \'some message from me to you #1 or #2\'

(only the first # is a delimiter)

50#some message from me to you #1 or #2

into

array 
(
    [amount] => 50
    [message] =>开发者_JS百科 'some message from me to you #1 or #2'
)


You don't need regex for such a simple split. The following will split your string correctly:

explode('#', $string, 2)

This will return an array like:

Array
(
    [0] => '50'
    [1] => 'some message from me to you #1 or #2'
)

See explode for more details.

If your query does end up getting more complex, then look at preg_split.

0

精彩评论

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

关注公众号