I have following symbols which preg_replace replaces:
$replace = '/[^a-zA-Z0-9]/';
in my code I use:
print "<a href='".preg_replace($replace, '-', $p->name)."-pr-".$p->id.".html'>";
The result of the above is the following:
Apple-iPad-2-Wi-Fi---3G-16GB-White-Tablet---MC982NFA-p-110341697.html
What do I have to do in order for it to only replace the symbols stated above with only one “-“, like the below example:
Apple-iPad-2-Wi-Fi-3G-16GB-White-Tablet-MC982NFA-p-110341697.html
Just add a
+to the expression, to match one or more occurences:Although the expression can be made shorter as: