开发者

PHP How to remove numbers like [3][2][4] from string using php

开发者 https://www.devze.com 2023-01-07 04:01 出处:网络
I have a text string that contain some references numbers like [3][2][4] o开发者_开发知识库r [1] or [5][7]

I have a text string that contain some references numbers like [3][2][4] o开发者_开发知识库r [1] or [5][7]

can you please help me removing all numbers between brackets ex. [4] from that string

using regular expressions Regex ?

Thanks


Just do a preg replace on /\[\d\]/ and replace it with ''

$s = preg_replace( '#\[\d+\]#', '', $context );

I believe that will kill multiple occurrences.


Since the question asks to remove numbers between the brackets and not the brackets themselves, I think this would be what he is looking for:

$string = preg_replace('/(?<=\[)\d+(?=\])/', '', $string);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号