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