Store html code in a variable using (php)

0

Saludes! it turns out that I have this little php code that extracts the source code of a page. HTML

<?php
$file = file('https://ged-tubesex69.rhcloud.com/demo.php');

foreach($file as  $line){
    $texto = nl2br(htmlspecialchars($line).' ');
echo $texto;
}
?>

The demo.php file contains the following code:

<head>
<title>video get</title>
</head>
<body>
<div id="xplayer">Loading the player...</div>
<script type="text/javascript">
[{image: "http://img-l3.xvideos.com/videos/thumbs169ll/04/c9/cc/04c9cc14e4537a32342eaa7a5340eb32/04c9cc14e4537a32342eaa7a5340eb32.11.jpg"}]
[{file: "http://xvideos-im-acf62f00-7826421-mp4.s.loris.llnwd.net/videos/mp4/0/4/c/xvideos.com_04c9cc14e4537a32342eaa7a5340eb32.mp4?e=1503981742&ri=1024&rs=85&h=a45adb250614cea72c7684c33c7662ce",label: "360P",type: "video/mp4",provider: "video"}],
</script>
</body> 

What I'm looking for is to store the contents of demo.php in a variable and extract the url from the video and the image from that variable / strong>.

I tried it this way:

if (preg_match('#\[{file:[^"]*"([^"]*)"#', $line, $datos)) {
    $sd = $datos[1];
} else {
    $sd = 'error';
}
if (preg_match('#\[{image:[^"]*"([^"]*)"#',$line, $datos)) {
    $img = $datos[1];
} else {
    $img = 'error';
}

echo video: $sd;
echo imagen: $img;

But it does not work for me. I hope you can help me clarify this problem

    
asked by BotXtrem Solutions 29.08.2017 в 04:21
source

1 answer

2

When I try to get the code of a page and then filter it I do something like this:

//Procedimientos utilizando curl para obtener el response de la pagina.

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch,CURLOPT_HEADER,0); // Necesario para visualizar ñ y acentos.

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true );

curl_setopt($ch, CURLOPT_ENCODING, "gzip,deflate"); // This is what solved the issue (Accepting gzip encoding)   

$response = curl_exec($ch); //La variable response almacena el response de la pagina.

curl_close($ch);
$filtro = explode('<div id="asd">',$response,2);

Once you have the response of the page in a string, with the functions explode and strpos you are "enclosing" or finding the fragment you want. Greetings.

    
answered by 29.08.2017 / 04:39
source