从字符串中删除空格

Let*_*123 -1 php

我有一个人们输入多个代码的表单.现在,我想删除这些代码之间的空格.但是,我的代码似乎不起作用.有任何想法吗?

$codes = $_GET['codes'];
$spaces = strpos($codes, " ");

for($spaces; $spaces=0; $spaces--){
str_replace(" ", "", $codes);
echo $codes;
}
Run Code Online (Sandbox Code Playgroud)

编辑:我只是尝试了别的东西,但它仍然无法正常工作.我的意思是回声每次给我原始的字符串.

$codes = $_GET['codes'];
$cleancodes = str_replace(" ", "", $codes);
$cleancodes = trim(preg_replace('/\s\s+/', ' ', $cleancodes));
echo "<br / >" . $cleancodes;
Run Code Online (Sandbox Code Playgroud)

Hea*_*ner 5

$string = str_replace(' ', '', $string);
Run Code Online (Sandbox Code Playgroud)