Convert spaces to dash and lowercase with PHP

PHPServer Side ProgrammingProgramming

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
raja
Published on 07-Apr-2020 11:14:37
Advertisements