可能重复:
How exactly do Regular Expression word boundaries work in PHP?
如何才能将整个单词与preg_replace()
匹配?
$string = 'C:\wamp\www\global_tolerance_2012\global\models'
$new_string = str_replace('\\', '/',preg_replace('#(.*?)(global).*#', '$1', $string));
结果,
C:/wamp/www/
我想要的结果,
C:/wamp/www/global_tolerance_2012/
答案 0 :(得分:0)
$string = 'C:\wamp\www\global_tolerance_2012\global\models';
$new_string = str_replace( '\\', '/', $string );
$new_string = preg_replace('#/(local|global)/.*#si', '/', $new_string);