1
curl로 찍은 페이지의 urls를 바꾸고 이미지 및 링크에 대한 올바른 링크를 추가해야합니다. 내 PHP 컬 코드는 다음과 같습니다preg_replace change href에서 링크
//original links
<a href="http://host.org"><img src="./sec.png"></a>
<link href="./styles.css" type="text/css" />
<script src="./style.js"></script><br />
//fixed SRC path
<a href="http://host.org"><img src="http://google.com/./sec.png"></a>
<link href="./styles.css" type="text/css" />
<script src="http://google.com/./style.js"></script>
//fixed HREF path
<a href="http://google.com//google.com/./sec.png"></a>
<link href="http://google.com/./styles.css" type="text/css" />
<script src="http://google.com/./style.js"></script>
그러나 링크가있을 때 "는"그것은 모든 링크를 절단 만 HREF 값을 왼쪽 :
<?php
$result = '<a href="http://host.org"><img src="./sec.png"></a>
<link href="./styles.css" rel="alternate stylesheet" type="text/css" />
<script type="text/javascript" src="./style.js"></script>';
echo $result;
if (!preg_match('/src="https?:\/\/"/', $result)) {
$result = preg_replace('/src="(http:\/\/([^\/]+)\/)?([^"]+)"/', "src=\"http://google.com/\\3\"", $result);
}
echo $result;
if (!preg_match('/href="https?:\/\/"/', $result)) {
$result = preg_replace('/href="(http:\/\/([^\/]+)\/)?([^"]+)"/', "href=\"http://google.com/\\3\"", $result);
}
echo $result;
?>
출력이다.
//from
<a href="http://host.org"><img src="./sec.png"></a>
//to src fix:
<a href="http://host.org"><img src="http://google.com/./sec.png"></a>
//ERRRROR when href fix make :
<a href="http://google.com//google.com/.sec.png"></a>
모든 신체가 그것을 고칠 수 있습니까? 당신이
감사합니다 !!!!!! – Eugenia