1
的GIF ID我想一個PHP的正則表達式來從這些PHP的正則表達式得到giphy
http://i.giphy.com/VmzI60RQG0fuw.gif
https://media.giphy.com/media/VmzI60RQG0fuw/giphy.gif
http://giphy.com/gifs/VmzI60RQG0fuw
http://giphy.com/gifs/music-videos-mariah-carey-dreamlover-VmzI60RQG0fuw
我測試此提取ID(VmzI60RQG0fuw),但它不能在3概率工作
preg_match('~(media\.giphy\.com/media/([^ /]+)/giphy\.gif|i.giphy.com/([^ /]+).gif)~i', $this->url, $matches)
請注意,如果獨立分析URL,'。*'可以工作。如果它們在某些情況下出現,則需要用'\ S *'替換'。*',或者甚至可以用'[^ \ s> /] *' –
好,請添加這個http:// giphy。 com/gifs/VmzI60RQG0fuw –
它是:['https?://(?| media \ .giphy \ .com/media /([^/\ n] +)/ giphy \ .gif | i \ .giphy \ .com /([^ /\n]+)\.gif|giphy\.com/gifs/(?:.*-)?([^/ \ n] +))'](https:// regex101。 COM/R/eC9gL6/3)。請注意''[']''裏面的'\ n'是由於它是一個多行字符串演示而添加的,我不認爲你需要它在真實的代碼中。 –