繁体   English   中英

PHP DOMDocument节点。值替换

[英]PHP DOMDocument node.Value Replacement

我在email.php中有3个p标签

$output='<p>Hey Jim</p>';
$output.='<p>We appreciate you are looking at using our services!</p>';
$output.='<p>Thanks Again</p>';

我希望能够用newp1newp2newp3的文本newp1 test.php那些p标签中的文本。

$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>';
}

我目前正在回声他们以查看它们,但对如何真正替换它们一无所知。

在此示例中,不需要DOMDocument:

您可以在email.php中使用类似这样的内容:

$output='<p>##msg1##</p>';
$output.='<p>##ms2##</p>';
$output.='<p>##msg3##</p>';

并在test.php中:

$html = str_replace("##msg1##", $newp1, $html);
$html = str_replace("##msg2##", $newp2, $html);
$html = str_replace("##msg3##", $newp3, $html);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM