$input_lines = 'this photos {img='3512.jpg', alt='Title'} and {#img='3513.jpg', alt='Title2'} any image code here related to image must be replaced.';
echo preg_replace("/({\w+)/", "<img src='https://imgs.domain.com/images/$1' alt='$2'/>", $input_lines);
正規表現コード:特定のリンク
/({\w+)/
画像リンク:
{img='3512.jpg', alt='Title'}
と文で{img='3513.jpg', alt='Title2'}
。
変換:
this photos <img src='https://imgs.domain.com/images/3512.jpg' alt='Title'/>
と<img src='https://imgs.domain.com/images/3513.jpg' alt='Title2'/> any image code here related to image must be replaced.
私は文章中の画像リンクを取得しかし、正規表現コードで間違って何ですか?
パターンには1つのキャプチャグループしかありません。 –
https://ideone.com/vJHTsm –
を参照してください。@WiktorStribiżew私はあなたがダウンタウンを与えたと思うが、あなたは同時に反応した。あなたの答えをありがとう。あなたが望むなら、答えを書くことができます。私はあなたの答えを正確に記したいと思っています –