1

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.

1
  • 3
    Consider that you're stuffing some HTML directly into a command line. Think of how that HTML is going to appear to the shell... And consider that PHP has perfectly good html manipulation libraries available. There is absolutely ZERO reason to fire some html into a command line command just to run it through awk. Commented Aug 29, 2014 at 19:09

2 Answers 2

2

file_get_contents PHP function works well.

<?php
$var = file_get_contents("hi.php");
echo $var;
?> 
Sign up to request clarification or add additional context in comments.

3 Comments

This is a better way than my answer actually.
@user78050, yes but just make sure to specify the entire URL e.g. file_get_contents("example.com/hi.php");
thanks it worked perfectly, I'll accept the answer as soon as I can
1

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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.