I need PHP code to replace comma or whitespace with hyphen
For eg:
If $value = 'home garden'
or $value = 'home,garden'
,
i need result as home-garden
I tried $result = preg_replace('/\s+[\,]/', '-', trim($value));
, but no use..
Can someone explain it?
$result = preg_replace('/[ ,]+/', '-', trim($value));
Test:
$value = ' home ,garden , gardener ';
$result = preg_replace('/[ ,]+/', '-', trim($value));
echo $result;
//home-garden-gardener
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