


$Detail = $DOM->getElementsByTagName( ' td') $Header = $DOM->getElementsByTagName( ' th') In this tip, we store the value into variables $Header and $Detail respectively. We only want to get table element, so, we only need element table header (tag ) and table detail (tag ).

then we create a new DOMDocument instance (with this instance, we can access the webpage's DOM), and then we load variable $htmlContent to get its data. We have to load the content of the web page, hold the value into $htmlContent (or whatever you name it). Open index.php with your text editor (Notepad++ or whatever). These are the screenshot of tables from urls above.Īs I said before, those are the example tables that we want it to be the PHP array in this tip. The first one contains table of fruits, and the second one contains table of attendance list. Those are the example web pages with HTML table. (I've prepared it for testing our code here.) In folder ~/xampp/htdoc/M圜onverter, create a PHP file, name it as index.php(you can use Notepad or Notepad++).īefore we go far, take a look at these webpages. That is where we'll locate our PHP source code.įor the first step, we create a folder in ~/xampp/htdoc, name it M圜onverter. Go to ~/xampp/htdocfolder in your computer. When you already installed XAMPP, make sure you open XAMPP and start Apache with no error (Apache is a web server, it runs your PHP code when you open your browser and try to "play" your PHP code, so make sure it's running well). XAMPP: XAMPP Version 5.6.3 (PHP Version 5.6.3).
Php for loop in html table how to#
This tip will give you the simple explanation about how to do it in Windows environment. Maybe sometimes, you need to read HTML table's data from a website, and maybe you need to store the values into a database instead of just read it, and then you wonder how to do it in PHP, more specifically, you wonder how to convert data in HTML table into PHP array.
