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
Comments
Post a Comment