• <tfoot id='LNwg6'></tfoot>
    1. <legend id='LNwg6'><style id='LNwg6'><dir id='LNwg6'><q id='LNwg6'></q></dir></style></legend>
        <bdo id='LNwg6'></bdo><ul id='LNwg6'></ul>

      <small id='LNwg6'></small><noframes id='LNwg6'>

    2. <i id='LNwg6'><tr id='LNwg6'><dt id='LNwg6'><q id='LNwg6'><span id='LNwg6'><b id='LNwg6'><form id='LNwg6'><ins id='LNwg6'></ins><ul id='LNwg6'></ul><sub id='LNwg6'></sub></form><legend id='LNwg6'></legend><bdo id='LNwg6'><pre id='LNwg6'><center id='LNwg6'></center></pre></bdo></b><th id='LNwg6'></th></span></q></dt></tr></i><div id='LNwg6'><tfoot id='LNwg6'></tfoot><dl id='LNwg6'><fieldset id='LNwg6'></fieldset></dl></div>

        使用 PHP DOMDocument 更改标签属性值

        时间:2024-04-13
      1. <i id='33xs9'><tr id='33xs9'><dt id='33xs9'><q id='33xs9'><span id='33xs9'><b id='33xs9'><form id='33xs9'><ins id='33xs9'></ins><ul id='33xs9'></ul><sub id='33xs9'></sub></form><legend id='33xs9'></legend><bdo id='33xs9'><pre id='33xs9'><center id='33xs9'></center></pre></bdo></b><th id='33xs9'></th></span></q></dt></tr></i><div id='33xs9'><tfoot id='33xs9'></tfoot><dl id='33xs9'><fieldset id='33xs9'></fieldset></dl></div>
          <tbody id='33xs9'></tbody>

          • <legend id='33xs9'><style id='33xs9'><dir id='33xs9'><q id='33xs9'></q></dir></style></legend>
          • <small id='33xs9'></small><noframes id='33xs9'>

              • <bdo id='33xs9'></bdo><ul id='33xs9'></ul>
                <tfoot id='33xs9'></tfoot>

                  本文介绍了使用 PHP DOMDocument 更改标签属性值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想用 PHP DOMDocument 更改标签的属性值.

                  I want to change the value of the attribute of a tag with PHP DOMDocument.

                  例如,假设我们有这行 HTML:

                  For example, say we have this line of HTML:

                  <a href="http://foo.bar/">Click here</a>
                  

                  我在PHP中加载上述代码如下:

                  I load the above code in PHP as follows:

                  $dom = new domDocument;
                  $dom->loadHTML('<a href="http://foo.bar/">Click here</a>');
                  

                  我想使用 PHP 的 DOMDocument 扩展将href"值更改为http://google.com/".这可能吗?

                  I want to change the "href" value to "http://google.com/" using the DOMDocument extension of PHP. Is this possible?

                  一如既往地感谢您的帮助!

                  Thanks for the help as always!

                  推荐答案

                  $dom = new DOMDocument();
                  $dom->loadHTML('<a href="http://foo.bar/">Click here</a>');
                  
                  foreach ($dom->getElementsByTagName('a') as $item) {
                  
                      $item->setAttribute('href', 'http://google.com/');
                      echo $dom->saveHTML();
                      exit;
                  }
                  

                  这篇关于使用 PHP DOMDocument 更改标签属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:PHP 7 中属性的类型提示? 下一篇:php domdocument获取属性值所在的节点值

                  相关文章

                      <bdo id='frycs'></bdo><ul id='frycs'></ul>
                  1. <legend id='frycs'><style id='frycs'><dir id='frycs'><q id='frycs'></q></dir></style></legend>

                    <small id='frycs'></small><noframes id='frycs'>

                  2. <i id='frycs'><tr id='frycs'><dt id='frycs'><q id='frycs'><span id='frycs'><b id='frycs'><form id='frycs'><ins id='frycs'></ins><ul id='frycs'></ul><sub id='frycs'></sub></form><legend id='frycs'></legend><bdo id='frycs'><pre id='frycs'><center id='frycs'></center></pre></bdo></b><th id='frycs'></th></span></q></dt></tr></i><div id='frycs'><tfoot id='frycs'></tfoot><dl id='frycs'><fieldset id='frycs'></fieldset></dl></div>

                      <tfoot id='frycs'></tfoot>