replace spaces with _ in php

Rickstar picture Rickstar · May 16, 2010 · Viewed 31k times · Source

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

 $e_type = 'Hello World TEST';

can anyone help me please

Answer

Matt picture Matt · May 16, 2010

You want str_replace:

$e_type = str_replace(' ', '_', $e_type);