Hello,
I've tried a couple of techniques for stripping out white space within a string, but am having really odd results.
For instance, if I do this:
<?php
$name = 'Mobile Pet 2';
echo $name;?>
<?php
$name2 = strtr($name, " ", "");
echo $name2;
?>
It will return the string ($name2) with spaces exactly like $name.
For instance Mobile Pet 2
However if I put a character into the quotation marks, such as a y:
<?php
$name2 = strtr($name, " ", "y");
echo $name2;
?>
It will return MobileyPety2
Why on earth would this be happening?
I've also tried a function with preg_replace, same issue:
<?php
function dirify($s) {
$s = preg_replace('![\w\s]!','',$s); ## remove non-word/space chars.
$s = preg_replace('!\s+!','_',$s); ## change space chars to underscores.
return $s;
}
The remove non/word space bit does nothing but the change space characters to underscore works. I just don't get it.
Thanks for your help
siobhan