preg_replace php space code example Example: php preg_replace whitespace $id = "aa aa"; echo $id; preg_replace('/\s+/', '_', $id); echo $id;