dongwei8440 2013-12-19 05:36 采纳率: 100%
浏览 66
已采纳

从仅包含URL字符串中的特定单词的文本中获取图像URL

I use preg_match_all to get all images URLs from the text string:

preg_match_all('!http://[^?#]+\.(?:jpe?g|png|gif)!Ui', $text , $matches);
  • Unfortunately, this time I need to get only images that contains '/bigimage/' inside the initial string.

  • i.e. $matches array should have only contains image elements like:

  http://x/x/bigimage/x/x.jpg
  • How could I modify source command to get desired result?
  • 写回答

1条回答 默认 最新

  • doulao7998636570 2013-12-19 06:04
    关注

    try

    (http://(?:\w+/)*bigimage(?:/\w+)*((/\w).(?:jpe?g|png|gif)))
    

    for visualization https://www.debuggex.com/r/22db9byd3cTlIX6f

    Change the brackets () or capturing groups according to your need

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?