Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

replace spaces with _ in php

Tags:

php

spaces

i am trying to replace spaces with underscore '_' in the following variable

 $e_type = 'Hello World TEST';

can anyone help me please

like image 677
Rickstar Avatar asked May 16 '10 17:05

Rickstar


People also ask

How to change spaces into underscores in PHP?

if you have a parameter $string and want to replace it's apace to underscore(_). $string = "Hello All."; $newString = str_replace(' ', '_', $string);

How to replace spaces in string PHP?

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.

How to remove blank spaces in PHP?

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.

How to delete all spaces in string PHP?

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.


2 Answers

You want str_replace:

$e_type = str_replace(' ', '_', $e_type);
like image 73
Matt Avatar answered Oct 08 '22 21:10

Matt


str_replace

like image 43
Quentin Avatar answered Oct 08 '22 23:10

Quentin