It is very common requirement to do a task where you need to Replace space with Dash in PHP.
PHP has a function str_replace() function which takes 3 parameters:
i) look for that character
ii) replace with the character
iii) source string
Replace space with Dash in PHP |
For example : If the string is "Dhaka is the capital city of Bangladesh"
then the result will be "Dhaka_is_the_capital_city_of_Bangladesh"
Example code :
Output:
ASCII code of dash/Hyphen symbol :
Syntax:
str_replace( find, replace, string, count )
find the value to look for
replace the value to change with
string the value to search for
count to count the number of times it occurs
Other PHP related post:
- Using JSON inside PHP
- How to stop this from showing in php5 ? :: Warning: Cannot modify header information - headers already sent by
- php File Upload - Tutorial with Example
- Writing HTML code inside PHP
1 comment:
Thanks, this was the most clear and precise example I could find on the interwebs, works great, thanks!
Post a Comment