<legend id='4mSSb'><style id='4mSSb'><dir id='4mSSb'><q id='4mSSb'></q></dir></style></legend>

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

        <small id='4mSSb'></small><noframes id='4mSSb'>

        将相对 URL 更改为绝对 URL

        Change a relative URL to absolute URL(将相对 URL 更改为绝对 URL)
      1. <small id='nKCcv'></small><noframes id='nKCcv'>

          • <bdo id='nKCcv'></bdo><ul id='nKCcv'></ul>
              <tbody id='nKCcv'></tbody>

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

              1. <legend id='nKCcv'><style id='nKCcv'><dir id='nKCcv'><q id='nKCcv'></q></dir></style></legend>
                  <tfoot id='nKCcv'></tfoot>

                • 本文介绍了将相对 URL 更改为绝对 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  例如我有一个这样的字符串:

                  $html = '<a href="test.html">test</a><a href="http://mydomain.com/test.html">test</a><a href="http://otherdomain.com/test.html">test</a><a href="someothertest/otherdir/hi.html">hi</a>';

                  并且我想将绝对 url 附加到所有没有给出绝对域的 href 中.

                  $html = '<a href="http://mydomain.com/test.html">test</a><a href="http://mydomain.com/test.html">test</a><a href="http://otherdomain.com/test.html">test</a><a href="http://mydomain.com/someothertest/otherdir/hi.html">hi</a>';

                  最好的方法是什么?我猜正则表达式有什么问题,但我的正则表达式技能是 ** ;)

                  提前致谢!

                  解决方案

                  找到了一个好方法:

                  $html = preg_replace("#(<s*as+[^>]*hrefs*=s*["'])(?!http)([^"'>]+)(["'>]+)#", '$1http://mydomain.com/$2$3', $html);

                  如果您的 $html 中还有 mailto 链接,您可以使用 (?!http|mailto)

                  for example i've got a string like this:

                  $html = '
                              <a href="test.html">test</a>
                              <a href="http://mydomain.com/test.html">test</a>
                              <a href="http://otherdomain.com/test.html">test</a>
                              <a href="someothertest/otherdir/hi.html">hi</a>
                          ';
                  

                  and i want to append the absolute url to all hrefs where no abolute domain is given.

                  $html = '
                              <a href="http://mydomain.com/test.html">test</a>
                              <a href="http://mydomain.com/test.html">test</a>
                              <a href="http://otherdomain.com/test.html">test</a>
                              <a href="http://mydomain.com/someothertest/otherdir/hi.html">hi</a>
                          ';  
                  

                  whats the best way to do that? i guess something with RegEx, but my RegEx skills are ** ;)

                  thanks in advance!

                  解决方案

                  found a good way :

                  $html = preg_replace("#(<s*as+[^>]*hrefs*=s*["'])(?!http)([^"'>]+)(["'>]+)#", '$1http://mydomain.com/$2$3', $html);
                  

                  you can use (?!http|mailto) if you have also mailto links in your $html

                  这篇关于将相对 URL 更改为绝对 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                        • <bdo id='alGGO'></bdo><ul id='alGGO'></ul>

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

                            <tbody id='alGGO'></tbody>

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