0

私はRegexpal.comを使用していますが、このSOの質問を見ました

文字列を一致させないようにしています。

画像へのすべてのリンクを文字列で preg_replace する必要があります <<IMAGE:{link}>>(https?:\/\/)?\S*(jpg|png|jpeg|bmp|gif) ORなので前と同じですが ingを使おうと思っていwithoutました(https?://)

となることによって:

Hi there this is an image link https://facebook.com/images/2323.jpg
and this one is too mysite.org/1.png

次のようになります。

Hi there this is an image link
<<IMAGE:https://facebook.com/images/2323.jpg>> and this one is too
<<IMAGE:mysite.org/1.png>>
4

1 に答える 1

1

私はあなたがこれを望んでいると思います...

$str = 'Hi there this is an image link https://facebook.com/images/2323.jpg
and this one is too mysite.org/1.png';

$regex = '/((https?:\/\/)?\S*(jpg|png|jpeg|bmp|gif))/';

$str = preg_replace($regex, '<<IMAGE:$1>>', $str);
echo $str;

出力

Hi there this is an image link <<IMAGE:https://facebook.com/images/2323.jpg>>
and this one is too <<IMAGE:mysite.org/1.png>>

コードパッド

于 2013-02-05T12:15:18.800 に答える