Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple preg_match_all problem

Status
Not open for further replies.

unomateo

IS-IT--Management
May 9, 2006
38
0
0
US
I'm trying to add placeholders to an html file, then replace the placeholders with preg_match_all. This is the output with the below code:
Array ( [0] => Array ( [0] => newsletter_bookmarks][newsletter_cl_post] ) )

it is matching everything from the beginning [ to the very end ]...no matter what I do.

I need to return each placeholder in between the brackets []

Code:
$text = "[newsletter_bookmarks][newsletter_cl_post]";
$search = "/[^\[].*[$\]]/";   //search for 'functions'
preg_match_all($search, $text, $matches);
print_r($matches);
[\code]
 
Code:
$text = "[newsletter_bookmarks][newsletter_cl_post]";
$search = "/[^\[].*[$\]]/";   //search for 'functions'
preg_match_all($search, $text, $matches);
print_r($matches);
 
looks like I needed to add U to the search.

Code:
$search = "/[^\[].*[$\]]/U";
 
actually this is the proper string

$search = "/\[.*\]/U";
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top