<bdo id='jdPCb'></bdo><ul id='jdPCb'></ul>

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

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

  • <legend id='jdPCb'><style id='jdPCb'><dir id='jdPCb'><q id='jdPCb'></q></dir></style></legend>
    <tfoot id='jdPCb'></tfoot>

        将可点击的锚标签转换为 html 文档中的纯文本

        时间:2023-05-21
        • <bdo id='DZPDp'></bdo><ul id='DZPDp'></ul>
            <tbody id='DZPDp'></tbody>
        • <tfoot id='DZPDp'></tfoot>

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

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

                • 本文介绍了将可点击的锚标签转换为 html 文档中的纯文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我试图在我的内容中匹配 <a> 标签,并将它们替换为链接文本,后跟方括号中的 url 用于打印版本.

                  I am trying to match <a> tags within my content and replace them with the link text followed by the url in square brackets for a print-version.

                  如果只有href",则以下示例有效.如果 <a> 包含另一个属性,则匹配太多并且不会返回所需的结果.

                  The following example works if there is only the "href". If the <a> contains another attribute, it matches too much and doesn't return the desired result.

                  如何匹配 URL 和链接文本,仅此而已?

                  How can I match the URL and the link text and that's it?

                  这是我的代码:

                  <?php
                  $content = '<a href="http://www.website.com">This is a text link</a>';
                  $result = preg_replace('/<a href="(http://[A-Za-z0-9\.:/]{1,})">([\s\S]*?)</a>/',
                       '<strong>\2</strong> [\1]', $content);
                  echo $result;
                  ?> 
                  

                  想要的结果:

                  <strong>This is a text link </strong> [http://www.website.com]
                  

                  推荐答案

                  您可以使用 ? 使匹配变得不贪婪.您还应该考虑到 href 属性之前可能有一些属性.

                  You can make the match ungreedy using ?. You should also take into account there may be attributes before the href attribute.

                  $result = preg_replace('/<a [^>]*?href="(http://[A-Za-z0-9\.:/]+?)">([\s\S]*?)</a>/',
                      '<strong>\2</strong> [\1]', $content);
                  

                  这篇关于将可点击的锚标签转换为 html 文档中的纯文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:使用 PHP 转换所有类型的智能引号 下一篇:PHP - 替换图像中的颜色

                  相关文章

                  最新文章

                  <tfoot id='GqjG8'></tfoot>

                      <bdo id='GqjG8'></bdo><ul id='GqjG8'></ul>

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

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