I have a question,
How can I delete the
-
scripts from a text string?
I did the following but it does not work for me.
$cadena = "Mi-cadena-con-guiones";
$cadena = preg_replace('[\s+]',"", $cadena);
I have a question,
How can I delete the
-
scripts from a text string?
I did the following but it does not work for me.
$cadena = "Mi-cadena-con-guiones";
$cadena = preg_replace('[\s+]',"", $cadena);
To be able to delete the scripts you can do it this way:
str_replace("-","",$cadena);
What it will do is look for the scripts of that chain and replace them for whatever you like, in the example I left it ""
the result will be this:
Micadenaconespacios
The common way is to use str_replace()
:
$cadena = "Mi-cadena-con-guiones";
$str = str_replace("-", " ", $cadena);
echo $str;
but another option is to use explode()
and implode()
:
$str = "Mi-cadena-con-guiones";
$arr = explode("-",$string);
$str = implode(" ",$arr);
echo $str;
both options will result in:
Mi cadena con guiones
You decide if you want to replace the - for a space " "
or an empty space ""
.