开发者

get word before a :- sign in a string with regex

I need to get the amount before a :- sign. So the string开发者_Go百科 would be: bla bla 120:-

And then store only 120 in a variable


preg_match_all('!(\d+):-!', $string, $matches);
print_r($matches);

This should do it. It captures anything up to a whitespace before ":-"


The regex

/(-?\d+):-/

will capture any digits (and a negative sign, if it's there) before a ":-" in the string.

You can than parse that into a number and store it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜