I am trying to convert an underscore to dash in php.
hi i have a regular expression that converts white spaces to dash but how can i achieve underscore to dash?
$item = preg_replace('/\ +/', '-', $item);
I am trying to convert an underscore to dash in php.
hi i have a regular expression that converts white spaces to dash but how can i achieve underscore to dash?
$item = preg_replace('/\ +/', '-', $item);
You don't need a regular expression. Use str_replace
:
$item = str_replace('_', '-', $item);
You can convert both space and underscore to dash with one regex:
$item = preg_replace('/[ _]+/', '-', $item);