I have 3 p tags in email.php
$output='<p>Hey Jim</p>';
$output.='<p>We appreciate you are looking at using our services!</p>';
$output.='<p>Thanks Again</p>';
I want to be able to replace the text within those p tags on the fly from test.php
with the text from newp1
, newp2
, and newp3
.
$newp1 = "Hello Mark";
$newp2 = "We have scheduled your pick-up for tomorrow morning.";
$newp3 = "Any questions gives us a call.";
$url = 'email.php';
$html = file_get_contents($url);
$doc = new DOMDocument();
@$doc->loadHTML($html);
$nodes = $doc->getElementsByTagName('p');
foreach($nodes as $item ){
echo $item->nodeValue.'<br>';
}
I am currently echoing them to see them, but have no clue on how to actually replace them.
No DOMDocument required, in this example:
You can use in email.php something like that:
$output='<p>##msg1##</p>';
$output.='<p>##ms2##</p>';
$output.='<p>##msg3##</p>';
and in test.php:
$html = str_replace("##msg1##", $newp1, $html);
$html = str_replace("##msg2##", $newp2, $html);
$html = str_replace("##msg3##", $newp3, $html);