如何调用我从file_get_content获取的页面的css

Yah*_*hoo 2 css php hyperlink file-get-contents

我使用以下代码

<div id="content"> <?php
$homepage = file_get_contents("www.yahoo.com");
echo $homepage;
?></div>
Run Code Online (Sandbox Code Playgroud)

该页面显示正常,但没有样式表.我如何称呼这些样式表?

并且出现的链接无效(通过我的域显示)如何解决?

我用于iFrame的代码不起作用如下

 <script type="text/javascript"
        src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script type="text/javascript"> 

$(document).ready(function(){
  $("button").click(function(){


    var iframe = document.getElementById("frm");


        selection = getIframeSelectionText(iframe); 
        alert(selection);
        if(selection.length >= 3) 
        { el = $('body', $('iframe').contents());
        el.html(el.html().replace(selection, "<span class='highlight'>" + selection + "</span>"));
        }

  });
    });




function getIframeSelectionText(iframe) {
var win = iframe.contentWindow;
var doc = win.document;

if (win.getSelection) {  
return win.getSelection().toString();

} else if (doc.selection && doc.selection.createRange) {
return doc.selection.createRange().text;

}
}

    </script>
Run Code Online (Sandbox Code Playgroud)

Mat*_*ský 5

如果页面中的样式表URL是绝对的,则所有内容都应正确显示.否则,您必须在页面代码中修改其URL(str_replace或正则表达式).

此外,您可以预期至少某些页面样式会中断,因为您将整个HTML嵌入到"外来"HTML结构中.通常,HTML标记应始终是页面中最外面的标记.

我怀疑你会想出能为所有网站完美运行的解决方案.为什么不使用IFRAME呢?