$title=Canon PowerShot SX130IS 12.1 MP Digital Camera with 12x Wide
Angle Optical Image Stabilized Zoom with 3.0-Inch LCDCanon PowerShot
SX130IS 12.1 MP Digital Camera with 12x Wide Angle Optical Image
Stabilized Zoom with 3.0-Inch LCD
希望输出为:
$title = Canon PowerShot SX130IS
Without
在php中使用strpos
,因为有一组数据,其中string的位置不同.Hence想要删除一个模式之后的数据。 after 12.1 MP
我想删除所有内容。
所以任何人都可以告诉我我能为它写出什么样的模式。
e.g. 12.1 MP camera(red),14.1 MP camera(blue) many characters written after that to be removed of from it
请有人给我所需的模式!!
答案 0 :(得分:1)
如果您想处理不同的百万像素,可以使用以下内容:
preg_replace('/\s\d+\.?\d*\sMP.*/', "", "Canon PowerShot SX130IS 15.4 MP Digital Camera blabla");
另一个变化也是“... SX130IS / 15.4 MP ......”和“...... 15.4MP ......”将是:
preg_replace('/(\s|\/)\d+\.?\d*\s?MP.*/', "", "Canon PowerShot SX130IS 15.4 MP Digital Camera blabla");
答案 1 :(得分:1)
这将根据MP位置返回字符串值。
function foo($title) {
$title_array = explode(' ',$title);
foreach ($title_array as $key => $value) {
if($value === "MP"){
$title = implode(' ',array_slice($title_array, 0, $key));
return $title;
}
}
}
foo($title);
答案 2 :(得分:0)
list($result) = explode("MP", $title, 2);
$result[0] = 'Canon PowerShot SX130IS 12.1 MP'