Forum Moderators: coopster
ob_start();
$page="http://anywebsite.com/anypage"
include $page;
$pageHtml=ob_get_contents();
ob_clean();
after execution of above code, the variable $pageHtml will have compiled html code ,(definitely, not the server source code), sent for the browser from that server. and you can easily manipulate it anywhere in your code.
I tried that. When I echo $pageHTML and when i use var_dump it outputs blank, but when i use print_r it outputs 1 whats wrong? also when I use var_dump it echos strong(0) at the top...
I put it with a fucntion:
function getsrc($file){
ob_start();
include($file);
$src = ob_get_contents();
ob_clean();
return print_r($src);//I keep switching between var_dump($src), print_r($src), and just $src)
}
why would you need to use var_dump or print_r, print_r doesnt work on this simply because the returned object is a string, not an array. your function is perfectly allright, you just need to remove those calls for both print_r or var_dump
<?
function getsrc($file){
ob_start();
include($file);
$src = ob_get_contents();
ob_clean();
return $src;
}
echo getsrc("http://www.webmasterworld.com/forum88/10696.htm");
?>
I just tested it.
Regards
# Definitily I suggest this:
function getsrc($file)
{
ob_start();
include ($file);
$src = ob_get_contents();
ob_clean();
# kill < and >
# ------------
$src = str_replace('<', '<', $src);
$src = str_replace('>', '>', $src);
# ------------
# I want lines as lines
# ---------------------
return nl2br($src);
}
By the way, would be nice a colored output, don't you think?
Who dare to do it in a few lines?
---
"Is there a way to get the browser side code like when youclick view source"
what i suggested was 100% exactly what he asked, atleast as what i apprehended, if he would have asked for nice colored output, that is possible too, but thats his part of work, he didnt ask for discussion on that , i think.
and why to kill < and > and why need lines seperately, i dont think he did ask for it, did he? and if it's question of number of lines, i could do all this in ONE line.
regards
I am using it within a form so my code looks like this:
if(isset($_POST['showsrc'])){
$filename = $_POST['filename'];
$src = getsrc($filename);
if ($src){
$page = htmlspecialchars($src, ENT_QUOTES);
}
else{
$page = "Could not read source";
}
$num = $_POST['num'];
$date = $_POST['date'];
echo "Filename: {$filename}<br>Num: {$num}<br>Date: {$date}<br>Source: {$src}";
}
is something wrong with that?
echo "Filename: {$filename}<br>Num: {$num}<br>Date: {$date}<br>Source: {$src}"; // this will be parsed by browser.
echo "Filename: {$filename}<br>Num: {$num}<br>Date: {$date}<br>Source: {$page}"; // this will be shown as plain text