2012-02-24 45 views
1

我试图删除URL中的空格和&,并用 - 替换它。到目前为止,以下工作:删除URL中的空格和preg_replace

preg_replace('/\s+/', '-', $page->label) // whitepace gets replaced with -  
preg_replace('/\&/', '-', $page->label) // & gets replaced with - 

我想这一行,但我不能结合2.任何人都可以帮助吗? 非常感谢您提前。

回答

6

这应该保持一行很好。

$output = preg_replace('/\s+|&/', '-', $page->label); 
+0

伟大的作品!非常感谢你。 – Luka 2012-02-24 12:20:51

0
$test = preg_replace('/\s+/', '-', $page->label); 
$final_output = preg_replace('/\&/', '-', $test); 

尝试这样

0
preg_replace('/[&]|\s+/', '-', $page->label); 
0
$output = preg_replace('/([\s+|\&])/', '-', $page->label);