user3904830
user3904830

Reputation:

How to get content of iframe as a string using php?

I have a page which is only have strings, something like that:

Hi Hello World

when I do this:

<?php
$var="<iframe  src='hi.php'></iframe>";
echo $var;
?>

it worked perfectly

but when I want to do operations on the content strings it won't work:

<?php
$var="<iframe  src='hi.php'></iframe>";
$var2 =`echo $var | awk ' { print $1 } '`;
?>

what should I do?

NOTE: I don't want it with js like this, I want it with php.

Upvotes: 1

Views: 8152

Answers (2)

Stuart Miller
Stuart Miller

Reputation: 657

Creating an iframe in a string like that won't load the file in src. Your betting off using CURL to load the other page.

$ch = curl_init();  
curl_setopt($ch, CURLOPT_URL, 'hi.php');  
curl_setopt($ch, CURLOPT_HEADER, 0);  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  

$contents = curl_exec($ch);  
curl_close($ch);

Upvotes: 1

TechDude
TechDude

Reputation: 111

file_get_contents PHP function works well.

<?php
$var = file_get_contents("hi.php");
echo $var;
?> 

Upvotes: 2

Related Questions