I've been trying to remove some text... between two sets of brackts... for two hours i have tried everything... i've been to existing questions here and the answers don't work for me... so here goes what i have
我一直试图删除一些文本...在两组括号之间......两个小时我已经尝试了所有的东西......我已经在这里找到现有的问题并且答案对我不起作用......所以这就是我所拥有的
[attachment=0:randomID]<!-- ia0 -->randomIMGnam.png<!-- ia0 -->[/attachment:randomID]
i really want to remove all of this from the beginning of a string i was able to remove everything inside the brackets but failed everytime to get rid of the image name
我真的想从一个字符串的开头删除所有这一切我能够删除括号内的所有内容,但每次都失败,以摆脱图像名称
Yes this is from phpbb i've pulled it from my DB no problem but don't want it to be displayed when i echo it.
是的这是来自phpbb我已经从我的数据库中取出它没有问题,但是当我回应它时不希望它被显示。
thanks in advance i really hope I really hope someone can help
在此先感谢我真的希望我真的希望有人可以提供帮助
edit: what i've tried 1. $extension_pos = strrpos($entry, '<!-- ia0 -->'); // find position of the last dot, so where the extension starts $output = substr($entry, 0, $extension_pos) . '' . substr($entry, $extension_pos);
编辑:我尝试了什么1. $ extension_pos = strrpos($ entry,' '); //找到最后一个点的位置,所以扩展开始的地方是$ output = substr($ entry,0,$ extension_pos)。 ''。 substr($ entry,$ extension_pos);
2.$output= preg_replace('#\].*?\[#', '', $entry);
2. $ output = preg_replace('#\]。*?\ [#','',$ entry);
-
$output = preg_replace('/\[[^]]*\]/', '', $entry);
$ output = preg_replace('/ \ [[^]] * \] /','',$ entry);
-
$output explode(']', $entry);
$ output explode(']',$ entry);
-
$imagename = preg_replace('#([attachment.*?]).*?([/attachment.*?])#', '$1$2', $entry);
$ imagename = preg_replace('#([attachment。*?])。*?([/ attachment。*?])#','$ 1 $ 2',$ entry);
3 个解决方案
#1
0
You could use regular expression as in example:
您可以使用正则表达式,例如:
<?php
$string = 'test [attachment=0:randomID]randomIMGnam.png[/attachment:randomID] test2 [something]
test3
[/something] test4';
echo preg_replace('#(\[(.*)\](.*)\[/.*\])#Us','',$string);
// output test test2 test4
?>
#2
1
You can use this regex to replace:
您可以使用此正则表达式替换:
$string = ' [attachment=0:randomID]<!-- ia0 -->randomIMGnam.png<!-- ia0 -->[/attachment:randomID]';
$string = preg_replace('/\[(.*?)\]/', '', $string);
#3
0
Using regex might be heavy for this kind of task.
You could instead use a simple reasoning, whenever you meet a open bracket increment a counter by one, whenever you meet a close bracket decrement the counter by one.
对于这种任务,使用正则表达式可能很重要。你可以改为使用一个简单的推理,每当你遇到一个开括号增加一个计数器时,每当你遇到一个关闭括号时,减去一个计数器。
And as long as your counter is > 0 just ignore the characters.
只要您的计数器> 0,就可以忽略这些字符。
#1
0
You could use regular expression as in example:
您可以使用正则表达式,例如:
<?php
$string = 'test [attachment=0:randomID]randomIMGnam.png[/attachment:randomID] test2 [something]
test3
[/something] test4';
echo preg_replace('#(\[(.*)\](.*)\[/.*\])#Us','',$string);
// output test test2 test4
?>
#2
1
You can use this regex to replace:
您可以使用此正则表达式替换:
$string = ' [attachment=0:randomID]<!-- ia0 -->randomIMGnam.png<!-- ia0 -->[/attachment:randomID]';
$string = preg_replace('/\[(.*?)\]/', '', $string);
#3
0
Using regex might be heavy for this kind of task.
You could instead use a simple reasoning, whenever you meet a open bracket increment a counter by one, whenever you meet a close bracket decrement the counter by one.
对于这种任务,使用正则表达式可能很重要。你可以改为使用一个简单的推理,每当你遇到一个开括号增加一个计数器时,每当你遇到一个关闭括号时,减去一个计数器。
And as long as your counter is > 0 just ignore the characters.
只要您的计数器> 0,就可以忽略这些字符。