我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

如何使用PHP替换字符串中的开始和结束h1标签?

I have captured the <h1> tag and its inner contents from a webpage and I need to remove the <h1> and </h1> parts of the string. The problem is that I won't know if the tag is written as <h1> or <h1 id="something">, etc. I know I can write

$tag = str_replace("<h1>", '', $tag);
$tag = str_replace("</h1>", '', $tag); 

But how can I handle the more general case, where it may be <h1 id="something">, or something else?

Look at strip_tags http://php.net/manual/en/function.strip-tags.php

近期文章

  • 从Windows迁移到Linux服务器,现在出现会话错误
  • 为什么数组在PHP中为NULL?
  • 页面被要求两次
  • 在PHP中将String转换为DateTime
  • 删除字符串中的字符串
  • PHP RegEx和部分字符串
  • preg_replace删除文本和标签
  • 用户可以从我的源获取我的数据库信息
  • jQuery或PHP:比较文档
  • Ajax / Javascript用户状态更新
  • 如何根据启动页面上的选择加载自定义样式表?
  • 从Web抓取信息
  • Symfony 1.4路由:来自不同类的字段
  • 发布不工作
  • PHP中的Javascript警报框。 警报POPS时,删除灰色/白色背景
  • 终止与jQuery AJAX请求的连接,继续在服务器端处理php?
  • 如何利用图像缓存同时跟踪图像何时发生变化?
  • 排序多维数组[重复]
  • 如何在顶部获取div对象
  • 使用PHP中的方法链接的OOP

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华