I pull HTMl tags from the database. The HTML tag I have captured is as follows:
<label .... title="ClassHTML">HTMLTEXT</label>
I find the text with the title “ClassHTML” in the label with PHP and print it on the screen. It works smoothly. What I want to do is to update the text I have drawn. So I want to change the “HTMLTEXT” text. For example, I want it to become:
<label .... title="ClassHTML">NEW HTML TEXT</label>
How can I do that? I am pulling this text with the code below, I want to update this text as I want.
$QUERYSQL = "SELECT html_VALUE from ..."; $stmt = sqlsrv_query ($conn, $QUERYSQL); while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) { $getROW = $row['html_VALUE']; $classname = 'ClassHTML'; $dom = new DOMDocument; $dom->loadHTML($getROW); $xpath = new DOMXPath($dom); $results = $xpath->query("//*[@title='" . $classname . "']"); if ($results->length > 0) { echo $review = $results->item(0)->nodeValue; } }
Advertisement
Answer
Not 100% sure if you want this updated after you have echoed it or not. Of you do you will need to do it client side using JS.
If you just want to change what you are echoing , as suggested in the comments change the line
echo $review = $results->item(0)->nodeValue;
To
$review = 'NEW ' . $results->item(0)->nodeValue; echo($review);