我試圖刪除URL中的空格和&,並用 - 替換它。到目前爲止,以下工作:刪除URL中的空格和preg_replace
preg_replace('/\s+/', '-', $page->label) // whitepace gets replaced with -
preg_replace('/\&/', '-', $page->label) // & gets replaced with -
我想這一行,但我不能結合2.任何人都可以幫助嗎? 非常感謝您提前。
我試圖刪除URL中的空格和&,並用 - 替換它。到目前爲止,以下工作:刪除URL中的空格和preg_replace
preg_replace('/\s+/', '-', $page->label) // whitepace gets replaced with -
preg_replace('/\&/', '-', $page->label) // & gets replaced with -
我想這一行,但我不能結合2.任何人都可以幫助嗎? 非常感謝您提前。
這應該保持一行很好。
$output = preg_replace('/\s+|&/', '-', $page->label);
$test = preg_replace('/\s+/', '-', $page->label);
$final_output = preg_replace('/\&/', '-', $test);
嘗試這樣
如果你使用Zend框架,也許Zend View Escaspe更好。
preg_replace('/[&]|\s+/', '-', $page->label);
$output = preg_replace('/([\s+|\&])/', '-', $page->label);
偉大的作品!非常感謝你。 – Luka 2012-02-24 12:20:51