2015-04-02 63 views

回答

1

使用這個簡單的單行

echo substr("Olympus Stylus VG-165 mp",0,22); 
1
$var = preg_replace('# mp$#',' ',$var) ; // Remove if there is " mp" at the end 
$var = preg_replace('#^mp #',' ',$var) ; // Remove if "mp " on start 
$var = preg_replace('# mp #',' ',$var) ; // Remove if " mp " everywhere 
$var = trim($var) ; // Remove the extras space on start and end of the string 

的其他方法,使其:

function testMp($v) { return $v != 'mp' ; } // Function called by array_filter 
$words = explode(' ',$var) ; // Explode the words of the string in an array 
$words = array_filter($words,'testMp') ; // Test each word on the array and remove if "mp" found (via testMp) 
$var = implode(' ',$words) ; // Restore the words array into a simple string 
+0

如果mp在中心那麼。 – 2015-04-02 07:15:40

相關問題