I just need to check a string (php) for squared brackets. If there are squared bracket, I want to get it's content for further processing.
String:
This is just a
[needle]
example
As there is a squared bracket, I want to get it's value, which is "needle" in this example. Now I will get some value for needle in a SQL-DB and replace the bracket with that.
i.e. keyword "needle" will get the value "great" out of the DB, so the result would be:
This is just a
great
example
I tried to use str_replace
$content= str_replace('[]', '',$content);
but this is the wrong approach, as I first need to check for the value and send a SQL-query...
Update: I think the linked thread (Capturing text between square brackets in PHP) has a different question. As I don't just get the hits, but process these hits by replacing them. Therefore the mentioned function preg_replace_callback
is the best solution.