if you are interested in getting both matches (since you have 2 in the string) and repeat them, you should do something like this. I also used single quotes so as not to hide quotes inside the regular expression. In addition, the proposals of the units were used.
preg_match_all('/charset="([^"]+)"/', $subject, $result, PREG_PATTERN_ORDER); for ($i = 0; $i < count($result[0]); $i++) { # Matched text = $result[0][$i]; }
source share