
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
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
$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
- Related Articles
- Convert text to lowercase with CSS
- Count spaces, uppercase and lowercase in a sentence using C
- Adding dash between spaces in field name in MySQL?
- Java program to convert a string to lowercase and uppercase.
- C++ program to convert kth character to lowercase
- How to convert string to lowercase in TypeScript?
- Swift Program to Convert a String to Lowercase
- Convert string to lowercase or uppercase in Arduino
- Golang Program to convert a string into lowercase
- How to convert Python dictionary keys/values to lowercase?
- Is there a MySQL command to convert a string to lowercase?
- How to convert lowercase letters in string to uppercase in Python?
- Golang Program to convert Uppercase to Lowercase characters, using binary operator.
- How to Convert Lowercase to Proper or Sentence Case in Excel?
- How to convert color spaces in OpenCV using C++?

Advertisements