PHP - 如何删除以所需字符开头的子字符串?

Ok i have a random string comin from database like this

"Fruit Apple = 3 pcs"

sometime it can be

"Fruit Mangoes = 44 pcs ripe"

ok my question is how can i remove the substring starting from equal (=) character ?

like "= 3 pcs"
and "44 pcs ripe"

so the result string will be

Fruit Apple

or

Fruit Mangoes

Thanks in advance..

Hi you can use explode("=",$data) and you will get an array which contains left part in 0 index and right part on index 1

<?php
$str = "Fruit Apple = 3 pcs";
$str = preg_replace('/\s*=.*/', '', $str);
print $str;

prints: Fruit Apple

You can use strstr(,,true) for that.
E.g.

<?php
$src = array(
    "Fruit Apple = 3 pcs",
    "Fruit Mangoes = 44 pcs ripe"
);

foreach($src as $e ) {
    echo strstr($e, '=', true), "
";
}

prints

Fruit Apple 
Fruit Mangoes 

You can use a regular expression, even some people consider its a performance hit in the modern day computers

$str = "Fruit Mangoes = 44 pcs ripe";
$str = preg_replace("/\s=.*$/", "", $str);