douyinglan2599 2017-09-17 04:23
浏览 19
已采纳

在PHP中捕获两组方括号之间的文本

I need some way of capturing the text between two group of square brackets. So for example, the following string:

test test [foo] bar [/foo] test

I need to output "bar", but 'bar' is a variable word

How can I get the output I need?

  • 写回答

2条回答 默认 最新

  • doushi9856 2017-09-17 04:26
    关注

    Maybe with this simply expression:

    preg_match('/\](.*)\[/', 'test test [foo] bar [/foo] test', $match);
    echo trim($match[1]);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?