dpquu9206 2011-10-29 08:44 采纳率: 0%
浏览 10
已采纳

删除字符串周围的第一个' '实例

Hi I have the following situation where I have tags wrapped around my contents and the following input

[hello]

Text here

[/hello]

[hello]

Text here 2

[/hello]

The output is

[hello]

Text here

[/hello]

[hello]

Text here 2

[/hello]

The desired output should be

[hello]
Text here
[/hello][hello]
Text here 2
[/hello]

PS: THanks for the answer, but since its user input, there's a chance of spacing [hello]

Is there a way using php, to trim the first around the opening tag ([hello]) and closing tag([/hello])? Thanks

  • 写回答

2条回答 默认 最新

  • dongwuying0221 2011-10-29 09:16
    关注

    it's simple, in the other words you want to replace to

    $str = "[hello]
    
    Text here
    
    [/hello]
    
    [hello]
    
    Text here 2
    
    [/hello]";
    echo str_replace("
    
    ", "
    ", $str);
    

    it will output

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

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题