从文本的中间我需要删减一个句子或更好地了解有关产品成分的信息。背后的逻辑总是一样的。以“成分”开头,以点“。”结尾。
例如(这是我的$prodDesc
):
Coca Cola is the most famous soft drink in America.
Ingredients: Carbon water, Sugar (sucrose or high-fructose corn syrup (HFCS) depending on country of origin), Caramel colour (E150d), Phosphoric Acid, Caffeine (34 mg/12 fl oz), natural Flavours. Nutrition Facts: 1 Serving Per Container - Serving Size: 1 Can. Total Fat 0g Sodium 45mg Total Carbohydrate 39g Total Sugars (Includes 39g Added Sugars) Cholesterol 0mg Protein 0g Vitamin D 0g Calcium 0g Iron 0g Potassium 0g
到目前为止,我尝试过,strpros
但事实上它位于文本的中间,我从“成分”到最后都得到了所有内容。
我只需要这个作为输出:
$prodIngredientsData = "Ingredients: Carbon water, Sugar (sucrose or high-fructose corn syrup (HFCS) depending on country of origin), Caramel colour (E150d), Phosphoric Acid, Caffeine (34 mg/12 fl oz), natural Flavours."
鉴于 $prodDesc 是上面的描述,我的尝试是:
$searchstring = $prodDesc;
$prodIngredientsData = false;
if (strpos($searchstring, "Ingredients") !== false)
{
$sd_array = explode("Ingredients", $searchstring);
$sd = end($sd_array);
$prodIngredientsData = "Ingredients " . $sd;
}
else {
$prodIngredientsData = false;
}
但如前所述,我从“成分”开始直到描述结束。但它应该在示例中的第一个句号处停止,即“成分... ...天然香料”。