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

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

      <bdo id='fmohR'></bdo><ul id='fmohR'></ul>
    <tfoot id='fmohR'></tfoot>

        使用php获取html标签中的内容并在处理后替换它

        Get content within a html tag using php and replace it after processing(使用php获取html标签中的内容并在处理后替换它)
        <legend id='W4RHv'><style id='W4RHv'><dir id='W4RHv'><q id='W4RHv'></q></dir></style></legend>
        <tfoot id='W4RHv'></tfoot>

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

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

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

                  <tbody id='W4RHv'></tbody>

                • 本文介绍了使用php获取html标签中的内容并在处理后替换它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个这样的 html (sample.html):

                  <头><身体><div id="内容"><!--内容--><p>一些内容</p><!--内容-->

                  如何使用 php 获取位于 2 个 html 注释 '<!--content-->' 之间的内容部分?我想得到那个,做一些处理然后放回去,所以我必须得到和放!可能吗?

                  解决方案

                  esafwan - 您可以使用正则表达式来提取 div(特定 id)之间的内容.

                  我之前为图片标签做过这件事,所以同样的规则也适用.我会查看代码并稍后更新消息.

                  [更新]试试这个:

                  ]*'.$attr.'="'.$value.'">(.*?)<\/div>/si';preg_match($tag_regex,$xml,$匹配);返回 $matches[1];}$yourentirehtml = file_get_contents("test.html");$extract = get_tag('id', 'content', $yourentirehtml);回声 $extract;?>

                  或者更简单:

                  preg_match("/

                  ]*id="content">(.*?)<\/div>/si", $text, $match);$content = $match[1];

                  吉姆

                  I have an html (sample.html) like this:

                  <html>
                  <head>
                  </head>
                  <body>
                  <div id="content">
                  <!--content-->
                  
                  <p>some content</p>
                  
                  <!--content-->
                  </div>
                  </body>
                  </html>
                  

                  How do i get the content part that is between the 2 html comment '<!--content-->' using php? I want to get that, do some processing and place it back, so i have to get and put! Is it possible?

                  解决方案

                  esafwan - you could use a regex expression to extract the content between the div (of a certain id).

                  I've done this for image tags before, so the same rules apply. i'll look out the code and update the message in a bit.

                  [update] try this:

                  <?php
                      function get_tag( $attr, $value, $xml ) {
                  
                          $attr = preg_quote($attr);
                          $value = preg_quote($value);
                  
                          $tag_regex = '/<div[^>]*'.$attr.'="'.$value.'">(.*?)<\/div>/si';
                  
                          preg_match($tag_regex,
                          $xml,
                          $matches);
                          return $matches[1];
                      }
                  
                      $yourentirehtml = file_get_contents("test.html");
                      $extract = get_tag('id', 'content', $yourentirehtml);
                      echo $extract;
                  ?>
                  

                  or more simply:

                  preg_match("/<div[^>]*id="content">(.*?)<\/div>/si", $text, $match);
                  $content = $match[1]; 
                  

                  jim

                  这篇关于使用php获取html标签中的内容并在处理后替换它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 的问题)
                    <tbody id='lxKse'></tbody>
                  1. <small id='lxKse'></small><noframes id='lxKse'>

                    <legend id='lxKse'><style id='lxKse'><dir id='lxKse'><q id='lxKse'></q></dir></style></legend>
                        <bdo id='lxKse'></bdo><ul id='lxKse'></ul>

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

                          <tfoot id='lxKse'></tfoot>