I have this piece of code:
$xpath = new DOMXPath($dom);
foreach ($xpath->query("//text()") as $q) {
foreach(preg_split("/(\r?\n)/", $q->nodeValue) as $line) {
$str = trim($line);
$translation = search_in_db_for_translation($str);
if (!empty($translation) {
replace string previously found by $translation
}
}
}
The script searches in an XML document for each string and if there is an available translation in the database (pairs {“input language string”, “input language string”}) it must replace the string in the DOM document (after this translation there are more DOM manipulations). The problem is I’m unable to find a function to do this.
EDIT: In order to be clear, what I need is a way to modify the current line and only the current line ($line var or $q->nodeValue). Please see JWiley answer and my comment.
The answer is as easy as:
It will replace the text and after this I just have to do a
$dom->saveHTMLFile($out)in order to save the HTML file.