比如
src="images/screenshots/3.jpg"
href="styles/sifrscreen.css"
<script src="scripts/functions.js"如果是"images/" 替换为 "www.xxx.com/site1/images"
如果是"/images/" 替换为 "www.xxx.com/images"
如果是本身就是绝对地址,就不替换.能解决的话,再给一百分,多谢了
顶者有分...

解决方案 »

  1.   

    你的要求描述不清,以下内容供參考:$_SERVER['HTTP_HOST']取服務器的域名
    dirname(__FILE__)獲取當前文件的絕對路徑$URL = $_SERVER['HTTP_HOST'].dirname(__FILE__)
      

  2.   

    比如抓取的网站是www.abc.com,那么它的html里肯定有很多相对路径的图片和css拉
    那么我想把它们变成绝对路径,以便能正常显示
      

  3.   

    $str = ' 
    <img src="images/screenshots/3.jpg" />
    <link href="styles/sifrscreen.css" />
    <script src="scripts/functions.js" />
    <img src="/images/aa.gif" />
    ';
    $str = preg_replace('/(?<=src=[\'"])(?!(\/|http:))/sm', 'http://www.xxx.com/site1/', $str);
    $str = preg_replace('/(?<=src=[\'"])(?=\\/)/sm', 'http://www.xxx.com/', $str);
    $str = preg_replace('/(?<=href=[\'"])(?!(\/|http:))/sm', 'http://www.xxx.com/site1/', $str);
    $str = preg_replace('/(?<=href=[\'"])(?=\\/)/sm', 'http://www.xxx.com/', $str);
      

  4.   

    多了个斜杠,小改了下
    $str = '<img src="images/screenshots/3.jpg" />
    <link href="styles/sifrscreen.css" />
    <script src="scripts/functions.js" />
    <img src="/images/aa.gif" />
    ';
    $str = preg_replace('/(?<=src=[\'"])(?!(\/|http:))/sm', 'http://www.xxx.com/site1/', $str);
    $str = preg_replace('/(?<=src=[\'"])(?=\\/)/sm', 'http://www.xxx.com', $str);
    $str = preg_replace('/(?<=href=[\'"])(?!(\/|http:))/sm', 'http://www.xxx.com/site1/', $str);
    $str = preg_replace('/(?<=href=[\'"])(?=\\/)/sm', 'http://www.xxx.com', $str);
    echo $str;
      

  5.   

    测试这个看看,赫赫
    $str = file_get_contents('http://www.mozillaonline.com/');
    $str = preg_replace('/(?<=src=[\'"])(?!(\/|http))/sm', 'http://www.mozillaonline.com/', $str);
    $str = preg_replace('/(?<=src=[\'"])(?=\\/)/sm', 'http://www.mozillaonline.com', $str);
    $str = preg_replace('/(?<=href=[\'"])(?!(\/|http))/sm', 'http://www.mozillaonline.com/', $str);
    $str = preg_replace('/(?<=href=[\'"])(?=\\/)/sm', 'http://www.mozillaonline.com', $str);
    echo $str;
      

  6.   

    下载PilotEdit 2.7, http://topic.csdn.net/u/20090723/07/33b39399-81ad-4fb1-a4a2-78509d2161a3.html用下面的正则表达式查找替换(做两次替换):
    查找:{src|href}="{images|styles|scripts}
    替换为:%01="www.xxx.com/%03
    查找:{src|href}="/
    替换为:%01="www.xxx.com/
    假设原始文件为:
    src="images/screenshots/3.jpg"
    href="styles/sifrscreen.css"
    <script src="scripts/functions.js" 
    src="/images/screenshots/3.jpg"
    href="/styles/sifrscreen.css"
    <script src="/scripts/functions.js"
     
    将被转换为:
    src="www.xxx.com/images/screenshots/3.jpg"
    href="www.xxx.com/styles/sifrscreen.css"
    <script src="www.xxx.com/scripts/functions.js" 
    src="www.xxx.com/images/screenshots/3.jpg"
    src="www.xxx.com/styles/sifrscreen.css"
    <script src="www.xxx.com/scripts/functions.js" 
      

  7.   

    从你的目的性来看,你也可以换一种角度来做,根本不需要去替换。
    你可以这样:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>这里是标题</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript" src="http://www.我自己的网址.com/myscript.js"></script>
    <base href="http://www.抓取的网址.com/site1/" />
    </head>
    <body>
    <img src="http://www.我自己的网址.com/images/abc.jpg" />
    <!-- 抓取的内容 开始 -->
    <img src="images/screenshots/3.jpg" />
    <link rel="stylesheet" type="text/css" href="styles/sifrscreen.css" />
    <script src="scripts/functions.js"></script>
    <img src="/images/screenshots/3.jpg" />
    <link rel="stylesheet" type="text/css" href="/styles/sifrscreen.css" />
    <script src="/scripts/functions.js"></script>
    <!-- 抓取的内容 结束 -->
    </body>
    </html>
      

  8.   

    关键在于:html的head去加base用抓取网址,页面中所有自己的链接、资源一律写全网址。
    还有,如果写域名,记得一定要把“http://”写上,否则浏览器会把域名当做文件夹处理的。
      

  9.   

    那请问如果他抓取的网页网址是 http://www.sss.com/a.php
    这样还管用吗