we are working on a project, in which we have to replace html data with array values using PHP preg_replace()
please look at the codes
Codes
$html = new simple_html_dom();
$texts = array('Replace','the', 'asterisks','prefer','it','all','functions','will','replace','computer','strategic','casio','computing','smart');
$html->load("<body><div>Replace the asterisks in a list with numbers in order</div><div>or if you prefer it all condensed down into a single smart</div><li>Both functions will replace placeholder</li><li>smart</li></body>");
$sample = &$html->outertext ;
foreach($texts as $text){
$fine = trim($text);
$replace = '<u>'.$fine.'<\u>';
if(!empty($text)){
if (strpos($sample,$fine)){
$sample = preg_replace('/$fine/',$replace,$sample);
$html->save(); /// Update all the replaces on $html ;
}
}
}
echo $sample;
print the same $html
, not updated.