I have the following string: I [like, goats] You [like cats] He [likes, dogs] I only need to read in the content that are between '[]' into an array. So the print_r would output something like this: Array ( [0] => like, goats [1] => like cats [2] => like, dogs ) Any idea how I would do this? Thanks!
<?php $str = 'I [like, goats] You [like cats] He [likes, dogs]'; $array = array(); preg_match_all("/\[(.*?)\]/", $str, $array); print_r($array); PHP: