从字符串中删除特定类型的文本

Remove specific kind of text from a string

如何从字符串中删除价格字段?例如,我有 n 件商品的价格各不相同(价格经常变化)。 1) VIP 套餐(80.00 欧元) 2) 标准套餐(0.00 欧元) 3)红色组(25.00 欧元) ... ... n) 黄色礼包(10.00 欧元)

如何删除价格字段,并仅显示名称字段,例如: 1) 贵宾套餐 2) 标准套餐 3) 红组 ... ... n) 黄色包

我知道 'str_replace' 代码可以提供帮助,但我无法配置它。如果可以请帮忙。

str_replace(array('text to replace', 'more text to replace'), '', $the_string);

# str_replace( 'what to search for', 'what to replace with', $variable );
# note that you can use an array or a string for that first argument.

由于价格是动态的,您可以使用 explode('(', $string)[0]

    <?php
preg_match_all("|<[^>]+>(.*)</[^>]+>|U",
    "<b>example: </b><div align=left>this is a test</div>",
    $out, PREG_PATTERN_ORDER);
echo $out[0][0] . ", " . $out[0][1] . "\n";
echo $out[1][0] . ", " . $out[1][1] . "\n";
?>