php - preg_replace not ignoring [] from string -


this code :

$string = "hello text [readmore] , remaining text"; echo preg_replace("[readmore]","",$string); 

this expected output :

hello text , remaining text 

this actual output :

hello text [] , remaining text 

question simple how ride of "[]" ?

you need escape [ & ]. try below regexp,

preg_replace("/\[([^\[\]]++|(?r))*+\]/", "", $string); 

output:

hello text , remaining text 

codepad demo.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -