14

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

 $e_type = 'Hello World TEST';

can anyone help me please

Dezefy
  • 2,048
  • 1
  • 14
  • 23
Rickstar
  • 6,057
  • 21
  • 55
  • 74
  • 1
    Downvote because its such a "lazy" question to post or leave it alone because it is still a valid question? Tough – Galen May 16 '10 at 17:58
  • You would have much less work todo if you used google. ;-) http://www.google.ch/search?q=php%20string%20replace%20spaces%20with%20underscore – Sandro Meier Nov 13 '11 at 12:41
  • @sandro but we try to get rid of google, stackoverflow is so much better :-) – mario Jan 17 '17 at 18:37

3 Answers3

51

You want str_replace:

$e_type = str_replace(' ', '_', $e_type);
Dominic Rodger
  • 97,747
  • 36
  • 197
  • 212
Matt
  • 43,482
  • 6
  • 101
  • 102
8

str_replace

Nate
  • 12,499
  • 5
  • 45
  • 60
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
4

Check this. You have some nice examples there...

Chathuranga Chandrasekara
  • 20,548
  • 30
  • 97
  • 138