dougan6982 2013-12-17 12:28
浏览 98
已采纳

通过PHP从字符串中删除特定的XML标记

I need to remove only the specific tag </licenses> from an XML file saved to a variable.

I've tried this, but I'm not getting the expected output:

<?php

  print preg_replace("</licenses>", "", "</licenses>");

?>

Returns:

<>

And surprisingly, the following removes the contents of all tags:

<?php

  print preg_replace("<>", "", "</licenses>");

?>

All I can think is that I'm somehow hitting a regex pattern or something. How can I do this?

  • 写回答

2条回答 默认 最新

  • dongtan5811 2013-12-17 12:30
    关注

    You need to use regex delimiter in the first argument of preg_replace which is a regex:

     echo preg_replace("#</licenses>#", "", "</licenses>");
    

    This will return an empty string as expected.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据