I'm working on code that replaces strings in "index.html" file and there is a repeated string inside HTML tags l. I'm using PHP to replace string with another one
The problem is that string may be repeated in many tags so how to make PHP code change string inside tags with certain id, because this PHP code replace all strings inside file
$(document).ready(function () {
$("p").click(function () {
var mid= this.id;
var yyy = document.getElementById(mid).innerHTML;
document.getElementById("oldvalue").value = yyy;
document.getElementById("iddddd").value=mid;
document.getElementById("newvalue").value ="text2"
});
});
<p id="parg1" >text1 </p>
<p id="parg2">text1 </p>
<form action="changeText.php" method="POST" >
<input type="hidden" id="oldvalue" name="oldvalue" class="inputText">
<input type="hidden" id="newvalue" name="newvalue" class="inputText" >
<input type="hidden" id="iddddd" name="id" class="inputText">
<input type="submit" id="submitbutton" value="Save" >
</form>
//php code
$content=file_get_contents("index.html");
$content_chunks=explode($_POST['oldvalue'], $content);
$content=implode($_POST['newvalue'], $content_chunks);
file_put_contents("index.html", $content);
//result from that is
//<p id="parg1" >text2 </p>
//<p id="parg2">text2 </p>
</div>