I want to extend my current preg_replace code and also replace all dots (.).
How can I extend my code, everything I try does not work.
<?php $optiontitleok = preg_replace('/(\s|&(amp;)?)+/', '', $optiontitle);?>
You are searching for whitespace-characters OR ampersands, the below pattern also includes a check for periods (whitespace OR ampersands OR dots):
<?php $optiontitleok = preg_replace('/(\s|&(amp;)?|\.)+/', '', $optiontitle);?>
When in doubt building your regex, this site is a goldmine:
https://regex101.com
Hope this helps!
EDIT
As I stated in the comments I don't believe you are testing for and replacing the "+" signs. You're using it as a quantyfier at the end of your group. To replace whitespace, ampersands, plus-signs and periods, you could use the following pattern:
\s|\&|\.|\+
Result:
<?php $optiontitleok = preg_replace('/\s|\&|\.|\+/', '', $optiontitle);?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With