Last active
December 8, 2023 02:36
-
-
Save vihoangson/1d0c4d5b9de97d29d72ee1dda7256f6c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//============ ============ ============ ============ | |
// Convert html table to aray | |
// | |
// @auth: ViHoangSon | |
// @since: 20160704092752 | |
// | |
// Using: | |
// $contents = "<table><tr><td>Row 1 Column 1</td><td>Row 1 Column 2</td></tr><tr><td>Row 2 Column 1</td><td>Row 2 Column 2</td></tr></table>"; | |
// $array = ConvertHelper::getdata($contents); | |
//============ ============ ============ ============ | |
class ConvertHelper{ | |
static function getdata($contents) | |
{ | |
$DOM = new DOMDocument; | |
$DOM->loadHTML($contents); | |
$items = $DOM->getElementsByTagName('tr'); | |
$return = array(); | |
foreach ($items as $node) { | |
$return[] = self::tdrows($node->childNodes); | |
} | |
return $return; | |
} | |
static function tdrows($elements) | |
{ | |
$str = array(); | |
foreach ($elements as $element) { | |
$str[] = $element->nodeValue; | |
} | |
return $str; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, i got an issue,
the TD are not in the array