I have a code that searches tags in .html file but I have problem executing the script it leads me to undefined index.
on my previous QUESTION I ask about searching id tags and I't leads me to used it as a reference. Enhancing the code and executing the code correctly but it shows me an error. The error searches every id tags in a .html file
CODE:
<?php
function getElementById($matches)
{
global $data;
return $matches[1].$matches[3].$matches[4].$data[$matches[3]].$matches[6];
}
$data['test'] = 'A';
$filename = 'test.html';
$html = file_exists($filename) ? file_get_contents($filename) : die('can\'t open the file');
$_HTML = preg_replace_callback('#(<([a-zA-Z]+)[^>]*id=")(.*?)("[^>]*>)([^<]*?)(</\\2>)#ism', 'getElementById', $html);
echo $_HTML;
?>
HTML:
<html>
<head>
<title>TEST</title>
</head>
<body>
<div id="test"></div>
<div id="test2"></div>
</body>
</html>
OUTPUT: PRINTSCREEN