I am encountering some unexpected behavior in some string manipulation.
I retrieve a set of values from a database to use in a SELECT box. The values in the database occasionally have some # of leading and trailing spaces, with text:
example) " udl udl "
In order to represent them accurately in the SELECT box, I use strtr to replace all SPACES with * character, so the above text becomes:
example) "*udludl**"
The STRTR command is basically $string=strtr("*"," ",$oldstring)
This part appears to work as expected.
This value gets passed to the next page on submission.
Before I can put the value into the database, I must convert the * back into spaces.
using a similar STRTR command $string=strtr(" ","*",$oldstring)
I get unexpected results. It replaces any leading or trailing with NO SPACES, and any between two alpha characters with a SINGLE SPACE, instead of one space for each * so the output is:
example) "udl udl"
Can anyone assist me with this unusual result.
I don't want to parse the $oldstring one character at a time to recreate a new string with the proper # of spaces. I wonder if the fact that the character is a SPACE is somehow at the root of the issue.
feel free to reply here or drop me an email at rorykost@hotmail.com