-2

Is it possible, using PHP, to get the current HTML loaded into a browser, as a string in PHP?

In other words, this would be the PHP equivalent of document.documentElement.outerHTML in JavaScript.

The question has probably been asked somewhere here, but I can't seem to find it. If this question has already been asked before, could you please give me link? I'm new here at StackOverflow :P

HDMemz
  • 3
  • 1
  • 1
    "get the current HTML loaded into a browser" <-- What? – AndrewL64 Mar 04 '17 at 17:52
  • You can pass the whole content of the HTML as a variable to PHP, look into ajax. Although, why would you want to do that?! – Geoff Mar 04 '17 at 17:53
  • If you go to any webpage (in Chrome), press F12, and look at the "Elements" section, there is a list of the current HTML loaded onto the webpage. I want to get this into a string in php – HDMemz Mar 04 '17 at 17:54
  • @HDMemz, why do you need to do that? – BenM Mar 04 '17 at 18:07
  • @BenM I'm trying to get text inside of a div with an id of "test". What I was going to do was get the entire html document into a string in php, and then load that into a DOMDoucment to do the rest – HDMemz Mar 04 '17 at 18:11
  • 1
    Why not use JS for this, and then pass the contents to PHP using AJAX? – BenM Mar 04 '17 at 18:12
  • @BenM Could you show me an example? I'm new to web development and only know HTML, CSS, JS (including jQuery), SQL, and PHP – HDMemz Mar 05 '17 at 18:18
  • If you know PHP and JS, you already know AJAX... Check the jQuery docs for AJAX. – BenM Mar 05 '17 at 18:19

1 Answers1

0

Yes, You can assign the html data using ob_start and ob_get_contents method

<?php 
    ob_start();
?>
<html>
   <head>
       <title>Test</title>
   </head>
   <body>
        Testings
    </body>
 </html>
 <?php 
    $data = ob_get_contents();
    ob_end_clean();
    print_r($data);
  ?>