簡體   English   中英

像字符串這樣的源代碼

[英]Source code like string

我有一個用於為某些網頁生成iframe的代碼,我需要在下面顯示該icframe的源代碼。 您也可以在www.pluspon.com/get3.php上看到我要執行的操作:

<?php 

error_reporting(E_ALL ^ E_NOTICE); 

$url = $_GET['url']; 

if( ! empty($url)) 
{ 
    $data = file_get_contents($url); 

    $data = str_replace('<head>', '<head><base href="'.$url.'" /></base>', $data); 

    $data = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $data); 
    $data = preg_replace('#<iframe(.*?)></iframe>#is', '', $data); 

    $data .=  
    ' 
    <script src="http://code.jquery.com/jquery-latest.js"></script> 
    <script> 
    $("div").each(function(i){ 
        if($(this).css("position") == "fixed") $(this).css("display", "none"); 
    }); 
    </script> 
    ' 
    ; 

    die($data);  
} 

?>


<iframe id="iframe" src="?url=http://kupime.com"></iframe></div>

現在,我需要顯示此iframe的源代碼,但是我嘗試使用:

  <?php echo htmlspecialchars(file_get_contents($_GET['url'])); ?>

但不起作用。 為什么? 你能告訴我一個人嗎?

更新:這是完整的代碼:

<?php 

error_reporting(E_ALL ^ E_NOTICE); 

$url = $_GET['url']; 

if( ! empty($url)) 
{ 
    $data = file_get_contents($url); 

    $data = str_replace('<head>', '<head><base href="'.$url.'" /></base>', $data); 

    $data = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $data); 
    $data = preg_replace('#<iframe(.*?)></iframe>#is', '', $data); 

    $data .=  
    ' 
    <script src="http://code.jquery.com/jquery-latest.js"></script> 
    <script> 
    $("div").each(function(i){ 
        if($(this).css("position") == "fixed") $(this).css("display", "none"); 
    }); 
    </script> 
    ' 
    ; 

    die($data);  
} 

?> 
<!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" xml:lang="en" lang="en"> 
<head> 
    <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
    <meta name="author" content="Webarto" /> 

    <title>AdriaMart</title> 

<script src="http://code.jquery.com/jquery-latest.js"></script> 

<style type="text/css"> 
<!-- 
iframe{width:100%;height:400px;} 
--> 
</style> 

</head> 
<body> 

<iframe id="iframe" src="?url=http://kupime.com"></iframe> 

</body> 
</html>

那是因為您在iframe中定義了url變量,但嘗試在其外部使用。 嘗試在您的php頁面上定義url,然后像下面一樣使用它

  <iframe id="iframe" src="?url=$url"></iframe></div>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM