
php修改id元素的方法:1、创建一个PHP示例文件;2、通过“str_replace("$oldString","$newString","$html");”方式实现替换即可。
本文 *** 作环境:Windows7系统、PHP7.1版、Dell G3电脑。
php怎么修改id元素?
PHP替换字符串中的id元素内容:
如:
$html = '<h1 id="item" class="abc" data="efg">Hello World';
修改方法:
$html = '<h1 id="item" class="abc" data="efg">Hello World';
$elementId ="item";
$newString ="Replace World";
$dom = new DOMDocument();
$dom->loadHTML($html);
$belement = $dom->getElementById("$elementId");
$oldString = $belement->nodeValue;
$newHTML = str_replace("$oldString","$newString","$html");
echo $newHTML;注意:请更改$elementId和$newString的原始值
推荐学习:《PHP视频教程》
以上就是php怎么修改id元素的详细内容,
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)