Convert spaces to dash and lowercase with PHP



The return value of strtolower can be passed as the third argument to str_replace (where $string is present). The str_replace function is used to replace a set of characters/character with a different set of character/string.

Example

 Live Demo

$str = 'hello have a good day everyone';
echo str_replace(' ', '-', strtolower($str));

Output

This will produce the following output −

hello-have-a-good-day-everyone
Updated on: 2020-04-07T11:16:11+05:30

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements