TL;DR;
You don't need preg_replace for this. Use str_replace instead.
See below for more detailed explanation.
It's probably important to note that brackets [] have special meaning in PCRE syntax as they indicate character classes. Which means that your pattern probably isn't doing what you expect it to do here.
For example
preg_replace('[]', 'foo', 'Lorem ipsum dolor sit amet, consectetur [] adipiscing elit. Phasellus quis lectus metus, at posuere neque.')
will give you
"fooLfooofoorfooefoomfoo fooifoopfoosfooufoomfoo foodfooofoolfooofoorfoo foosfooifootfoo fooafoomfooefootfoo,foo foocfooofoonfoosfooefoocfootfooefootfooufoorfoo foo[foo]foo fooafoodfooifoopfooifoosfoocfooifoonfoogfoo fooefoolfooifootfoo.foo fooPfoohfooafoosfooefoolfoolfooufoosfoo fooqfooufooifoosfoo foolfooefoocfootfooufoosfoo foomfooefootfooufoosfoo,foo fooafootfoo foopfooofoosfooufooefoorfooefoo foonfooefooqfooufooefoo.foo"
which is not likely what you want at all.
This is because PCRE also requires delimiters enclosing the pattern. Here the brackets will be treated as delimiters and you end up with an empty pattern.
It is also possible to use bracket style delimiters where the opening and closing brackets are the starting and ending delimiter, respectively. (), {}, [] and <> are all valid bracket style delimiter pairs.
Instead you should use
preg_replace('/\[\d*\]/', $replacement, $fulltext);
This escapes the brackets with the \ backslash character for literals and provides an optional number of digit characters to fall within the pattern matching expression.
If you wish for the replacement string to fall within the brackets themselves and not replace the actual brackets you can enclose the pattern in round braces and use back references to do the replacement.
If you want to match specific patterns to specific replacement strings (where the pattern is more complex than just a simple substring search/replace) then you should use preg_replace_callback_array instead. However, it's important to note that this function is only available in PHP 7
Example
$newText = preg_replace_callback_array(
[
'/\[(23)\]/' => function ($match) {
return 'foo';
},
'/\[(24)\]/' => function ($match) {
return 'bar';
},
],
$fulltext
);
Which would give you something like...
"Lorem ipsum dolor sit amet, consectetur foo adipiscing elit. Phasellus quis lectus metus, at posuere neque. Sed pharetra nibh bar eget orci convallis at posuere leo convallis. Sed blandit augue [25] vitae augue scelerisque bibendum. Vivamus sit amet libero turpis, non venenatis urna. In blandit, odio convallis suscipit venenatis, ante ipsum cursus [26] augue."
If what you really need is to do replacement based on substring search (such that [23] will be replaced with the string 'foo' and [24] will be replaced with the string 'bar', etc...) then you don't need a regular expression. Instead you can use str_replace for this.
Here's an example...
$fulltext = 'Lorem ipsum dolor sit amet, consectetur [23] adipiscing elit. Phasellus quis lectus metus, at posuere neque. Sed pharetra nibh [24] eget orci convallis at posuere leo convallis. Sed blandit augue [25] vitae augue scelerisque bibendum. Vivamus sit amet libero turpis, non venenatis urna. In blandit, odio convallis suscipit venenatis, ante ipsum cursus [26] augue.';
$searchStrings = [
'[23]',
'[24]',
'[25]',
'[26]',
];
$replacements = [
'[foo]',
'[bar]',
'[baz]',
'[quix]',
];
$newText = str_replace($searchStrings, $replacements, $fulltext);
Which gives you
"Lorem ipsum dolor sit amet, consectetur [foo] adipiscing elit. Phasellus quis lectus metus, at posuere neque. Sed pharetra nibh [bar] eget orci convallis at posuere leo convallis. Sed blandit augue [baz] vitae augue scelerisque bibendum. Vivamus sit amet libero turpis, non venenatis urna. In blandit, odio convallis suscipit venenatis, ante ipsum cursus [quix] augue."