From 7d99d11648d878e3052aa910c7e21b5bc85635c1 Mon Sep 17 00:00:00 2001 From: Linard Schwendener Date: Wed, 27 Nov 2019 00:20:52 +0100 Subject: [PATCH] Added Regex to recipeYield This takes the first uninterrupted string of numbers as the correct yield count. --- lib/Service/RecipeService.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/Service/RecipeService.php b/lib/Service/RecipeService.php index 190c1351..e07a86ed 100644 --- a/lib/Service/RecipeService.php +++ b/lib/Service/RecipeService.php @@ -168,7 +168,12 @@ class RecipeService // Make sure that "recipeYield" is an integer which is at least 1 if (isset($json['recipeYield']) && $json['recipeYield']) { - $yield = filter_var($json['recipeYield'], FILTER_SANITIZE_NUMBER_INT); + + $regex_matches = []; + preg_match('/^.*?(\d*)/', $json['recipeYield'], $regex_matches); + if (count($regex_matches) >= 1 ){ + $yield = filter_var($regex_matches[0], FILTER_SANITIZE_NUMBER_INT); + } if ($yield && $yield > 0) { $json['recipeYield'] = (int)$yield;