简体   繁体   中英

Source code like string

I have a this code for generating an iframe for some webpage and I need to show source code of that icframe below. You can also can see what I'm trying to do at 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>

NOW I need to show source code of this iframe but I try with:

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

but doen't work. Why? Can you tell me someone?

UPDATE: here is the full code:

<?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>

That is because you define url variable inside iframe but try to use outside of it. Try defineing url on your php page and then use it like below

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM