I am trying (with no success) to get all possible matches with preg_match_all().
Any help would be greatly apreciated. Thank you in advance.
No related questions and answers clearly give a way to do that.
Here is a typical example :
the code is :
$str = "manger des pâtes à la carbonara dans un restaurant de pâtes";
$pattern = "/(.*) (son |sa |ses |un |une |des |du |le |les |la)(.*) dans (son |sa |ses |un |une |de la |des |du |la |le |les |l')(.*)/";
if(preg_match_all($pattern, $str, $matches, PREG_SET_ORDER)) {
print_r($matches);
}
the result (correct but incomplete for what I want) is :
- Array ( [0] => Array ( [0] => manger des pâtes à la carbonara dans un restaurant de pâtes [1] => manger des pâtes à [2] => la [3] => carbonara [4] => un [5] => restaurant de pâtes ) )
what is missing is the following match :
- Array ( [0] => Array ( [0] => manger des pâtes à la carbonara dans un restaurant de pâtes [1] => manger [2] => des [3] => pâtes à la carbonara [4] => un [5] => restaurant de pâtes ) )
overall I would like to get :
- Array ( [0] => Array ( [0] => manger des pâtes à la carbonara dans un restaurant de pâtes [1] => manger des pâtes à [2] => la [3] => carbonara [4] => un [5] => restaurant de pâtes )
[1] => Array ( [0] => manger des pâtes à la carbonara dans un restaurant de pâtes [1] => manger [2] => des [3] => pâtes à la carbonara [4] => un [5] => restaurant de pâtes )
)