user278139
user278139

Reputation:

PHP Filter from string

I have a string in PHP for example $string = "Blabla [word]";

I would like to filter the word between the '[' brackets. The result should be like this $substring = "word";

thanks

Upvotes: 1

Views: 1457

Answers (2)

Piotr Pankowski
Piotr Pankowski

Reputation: 2406

Try:

preg_match ('/\[(.*)\]$/', $string, $matches);
$substring = $matches[1];

var_dump ($substring);

Upvotes: 1

SilentGhost
SilentGhost

Reputation: 319561

preg_match('/\[(.*?)\]/', $string, $match);
$substring = $match[1];

Upvotes: 3

Related Questions