답변 2개
채택된 답변
+20 포인트
8년 전
</p>
<p>//href내의 ?을 골뱅이로 치환
$str = '<a href="<a href="http://sir.kr/test.php?a=2"" target="_blank" rel="noopener noreferrer">http://sir.kr/test.php?a=2"</a> target="_blank" title="테스트">Sir.kr</a>
<a href="<a href="http://navycolor.com/test.php?a=2"" target="_blank" rel="noopener noreferrer">http://navycolor.com/test.php?a=2"</a> target="_blank" title="테스트">Navycolor.com</a>';</p>
<p>$pattern = "#<a href=(?:\"|\')(?<links>[^\"\']*)(?:\"|\')#i";</p>
<p>preg_match_all($pattern, $str, $matches);</p>
<p>for($i=0; $i < count($matches['links']); $i++){
$href = str_replace("?", "@", $matches['links'][$i]);</p>
<p> $str = str_replace($matches['links'][$i], $href, $str);
}</p>
<p>echo $str;</p>
<p>
로그인 후 평가할 수 있습니다
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인