Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 移除两个方括号之间的所有内容_Php_Html_Regex_Preg Replace_Phpbb - Fatal编程技术网

Php 移除两个方括号之间的所有内容

Php 移除两个方括号之间的所有内容,php,html,regex,preg-replace,phpbb,Php,Html,Regex,Preg Replace,Phpbb,我一直在试图删除一些文字。。。在两组支架之间。。。两个小时以来,我什么都试过了。。。我已经看过这里存在的问题,但答案对我来说并不适用。。。这就来了 我所拥有的 [attachment=0:randomID]<!-- ia0 -->randomIMGnam.png<!-- ia0 -->[/attachment:randomID] [attachment=0:randomID]randomIMGnam.png[/attachment:randomID] 我真的很想从一

我一直在试图删除一些文字。。。在两组支架之间。。。两个小时以来,我什么都试过了。。。我已经看过这里存在的问题,但答案对我来说并不适用。。。这就来了 我所拥有的

 [attachment=0:randomID]<!-- ia0 -->randomIMGnam.png<!-- ia0 -->[/attachment:randomID]
[attachment=0:randomID]randomIMGnam.png[/attachment:randomID]
我真的很想从一个字符串的开头删除所有这些,我可以删除括号内的所有内容,但每次都无法删除图像名称

是的,这是phpbb的,我已经从数据库中取出了。没问题,但我不想在回显时显示它

提前谢谢我真的希望我真的希望有人能帮忙

编辑:我试过的 1. <代码>$extension\u pos=strrpos($entry,');//找到最后一个点的位置,这样扩展就开始了 $output=substr($entry,0,$extension_pos)。“”。substr($entry,$extension_pos)

2.
$output=preg\u replace('\\].\[\\',''$entry);

  • $output=preg\u replace('/\[[^]*\]/','','',$entry)

  • $output explode(']',$entry)

  • $imagename=preg#u replace(“#”([attachment.*?]).*([/attachment.*?])#”,“$1$2”,$entry)


  • 您可以使用此正则表达式替换:

    $string = ' [attachment=0:randomID]<!-- ia0 -->randomIMGnam.png<!-- ia0 -->[/attachment:randomID]';
    $string = preg_replace('/\[(.*?)\]/', '', $string);
    
    $string='[attachment=0:randomID]randomIMGnam.png[/attachment:randomID];
    $string=preg\u replace('/\[(.*?\]/','','$string);
    
    您可以使用正则表达式,如示例所示:

    <?php
        $string = 'test [attachment=0:randomID]randomIMGnam.png[/attachment:randomID] test2 [something]
        test3
    
        [/something] test4';
    
    
        echo preg_replace('#(\[(.*)\](.*)\[/.*\])#Us','',$string);
        // output test test2 test4 
    
    
    ?>
    

    对于此类任务,使用正则表达式可能会很繁重。
    相反,您可以使用一个简单的推理,每当您遇到一个开括号时,计数器递增一,每当您遇到一个闭括号时,计数器递减一


    只要你的计数器大于0,就忽略字符。

    发布你尝试过的内容。。你可以使用
    REGEX
    进行查询this@Luke预期的输出是什么?警告:preg_replace():未知修饰符“g”@LukeVyner:-您可以删除
    g
    ,因为g在preg_replace()中是隐式的,您不需要包含它