开发者

Remove all characters after "-"

I thought this would work but it appears to be only removing the - and the whitespace after it.

$itemList[] = preg_replace('开发者_运维百科/-(.*?)/i', "", $temp['item']);


Try:

$itemList[] = preg_replace('/-(.*)$/i', "", $temp['item']);

The $ symbol matches the end of the input, so forces the .* to grab to the end.

Adding a ? after the * makes it un-greedy, meaning it will grab the minimum possible, not the maximum possible, so in this case it is exactly what you don't want.


Why were you using non-greedy *? ?

$itemList[] = preg_replace('/-.*/i', "", $temp['item']);

Also, the capturing parens were unnecessary.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜