I am trying to remove Whitespaces and & in a URL and replace it with a -. So far the following works:
preg_replace('/\s+/', '-', $page->label) // whitepace gets replaced with -
preg_replace('/\&/', '-', $page->label) // & gets replaced with -
I would like to have this in one line, but I am not able to combine the 2. Can anyone help? Thank you very much in advance.
This should keep it all nicely in one line.
$output = preg_replace('/\s+|&/', '-', $page->label);
$test = preg_replace('/\s+/', '-', $page->label);
$final_output = preg_replace('/\&/', '-', $test);
Try like this
if you use Zend Framework, maybe Zend View Escaspe is better.
preg_replace( '/[&]|\s+/', '-', $page->label );
$output = preg_replace('/([\s+|\&])/', '-', $page->label);