()
represent a capture group and will be represented in the $matches
array even if it is empty.
Either get rid of the ()
around the groups that are returning empty like (.*?)
to make it just .*?
(because presumably you don't want those returned) or tell the engine not to capture that with (?:
like (?:.*?)
.
#\[link.*?link\=\"(.*?)\".*?text\=\"(.*?)\"\]#e
Or if you do want those returned when they are not empty, then use +
instead of *
:
#\[link(.+?)link\=\"(.*?)\"(.+?)text\=\"(.*?)\"\]#e