PHP Greedy And Non-Greedy Matching – String Function

<?
$meats = "<b>Chicken</b>, <b>Beef</b>, <b>Duck</b>";preg_match_all('@<b>.*?</b>@',$meats,$matches);
foreach ($matches[0] as $meat) {
    print "Meat A: $meat\n";
}preg_match_all('@<b>.*</b>@',$meats,$matches);
foreach ($matches[0] as $meat) {
    print "Meat B: $meat\n";
}
?>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.