i am trying to replace spaces with underscore '_' in the following variable
$e_type = 'Hello World TEST';
can anyone help me please
if you have a parameter $string and want to replace it's apace to underscore(_). $string = "Hello All."; $newString = str_replace(' ', '_', $string);
Answer: Use the PHP str_replace() Function You can simply use the PHP str_replace() function to strip or remove all spaces inside a string.
The trim() function removes whitespace and other predefined characters from both sides of a string. Related functions: ltrim() - Removes whitespace or other predefined characters from the left side of a string.
The trim() function in PHP removes whitespace or any other predefined character from both the left and right sides of a string. ltrim() and rtrim() are used to remove these whitespaces or other characters from the left and right sides of the string.
You want str_replace
:
$e_type = str_replace(' ', '_', $e_type);
str_replace
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With