$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.
나는 문장에있는 이미지 링크를 얻을 수 있지만 정규식 코드에 어떤 문제가 있습니까?
패턴에 포착 그룹이 하나만 있습니다. –
https://ideone.com/vJHTsm –
@ WiktorStribiżew를보십시오. 당신은 아래쪽을 준다고 생각하지만 동시에 응답했습니다. 답해 주셔서 감사합니다. 원한다면 답을 쓸 수 있습니다.귀하의 답변에 정확하게 표시하고 싶습니다. –