I am using regex to extract content between different classes of tags, however I got the output: No matches thus help is required. I do understand that xpath or DOM Document would be a better choice instead of using regex however my project require me to use regex as xpath or DOM document would affect the later part of the project. Thanks
// Read php file using curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://localhost/page1.php");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
curl_close($ch);
$result = preg_replace("#(<\s*a\s+[^>]*href\s*=\s*[\"'])(?!http)([^\"'>]+)([\"'>]+)#",'$1http://localhost/page1.php/$2$3', $result);
//print out page1.php file content
#echo $result;
$data = $result;
$pattern = '{<!-- populate table from mysql database -->(.*?)\</tbody>}';
#$pattern = '{<div\s+class="name"\s*>((?:(?:(?!<div[^>]*>|</div>).)++(?=<div[^>]*>(?1)</div>)*))}si';
$matchcount = preg_match_all($pattern, $data, $matches);
if ($matchcount > 0) {
for($i = 0; $i < $matchcount; $i++) {
echo("
");
echo($matches[1][$i]);
}
} else {
echo('No matches');
}
HTML:
<tbody>
<!-- populate table from mysql database -->
<div class="student_information">
<tr>
<div class="admin"><td>140009K</td></div>
<div class="name"><td>Lee Tan</td></div>
<div class="hp"><td>96655568</td></div>
<div class="email"><td>140000K@gmail.com</td></div>
</tr>
</div>
<div class="student_information">
<tr>
<div class="admin"><td>1411111A</td></div>
<div class="name"><td>Sally Tan</td></div>
<div class="hp"><td>.</td></div>
<div class="email"><td>sally8@hotmail.com</td></div>
</tr>
</div>
</tbody>
Output should be:
140009K
Lee Tan
96655568
140000K@gmail.com
1411111A
Sally Tan
83954441
sally8@hotmail.com
What's wrong? Need help!