I am trying to create something where it will change all of the text on a webpage and re output it to the user. It will be changing words predefined in a database.
I am using http://simplehtmldom.sourceforge.net as my HTML parser. What i want todo is to change only the test inside of tags but not the tags. I thought this would work, If i echo out $e->plaintext
it will work but then it isn't styled.
<?php
// example of how to modify HTML contents
include('../simple_html_dom.php');
// get DOM from URL or file
$html = file_get_html('http://example.com/');
$e = $html->find("html", 0);
$text = $e->plaintext;
$con = mysqli_connect("localhost","root","root","Words");
$result = mysqli_query($con,"SELECT * FROM Wordsweb");
//replace all words
$English = array();
$Simple = array();
while ($row = mysqli_fetch_array($result)){
$English[] = $row['English'];
$Simple[] = $row['Simple'];
}
$e->plaintext = str_replace($English, $Simple,$e->plaintext);
echo $e;
?>
Thanks in advance!
p.s.: previously i was using preg_replace_callback
but i was advised to use this.