开发者

string function workout in php

开发者 https://www.devze.com 2022-12-30 10:17 出处:网络
I have the s开发者_Go百科tring like this, $inp1 = \"3 doses at 0[0,0], 1-2 and 6 Month[6,1] [3,2])\";

I have the s开发者_Go百科tring like this,

$inp1 = "3 doses at 0[0,0], 1-2 and 6 Month[6,1] [3,2])";

in this internally, going to take the values of square bracket. How can i take this values in the square bracket? any function is there to return the string like this

[0,0] [6,1] [3,2]

Thanks in advance for help.


preg_match_all('/\[\d+,\d+\]/', $inp1, $matches);
$result = implode(' ', $matches[0]);


you could try with the preg_replace function using a regular expression :

$s = "3 doses at 0[0,0], 1-2 and 6 Month[6,1] [3,2])";
$s = preg_replace("/[^\[]*(\[[^\]]*\])[^\[]*/","$1",$s);
echo $s;

This outputs

[0,0][6,1][3,2]
0

精彩评论

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