I'm trying to remove a forward-slash from the end of a string.
Seems simple, but I'm having some issues. A really weird charactar is showing up at the end of the string. See my code:
function removeSlash($currentURL)
{
if ( strpos($currentURL , '/') == (strlen($currentURL)-1) )
$currentURL = substr( $currentURL, 0, -1 );
return $currentURL;
}
$url = 'http://bob.com/';
var_dump( removeSlash($url) );
output:
string(15)"http://bob.com"
The above var_dump says 15 chars were returned, but there is actually 14...
So I ignore it. Then I write a little more code to store it in a DB. The invisible character emerges!
In phpMyAdmin, when i edit the row that the output was inserted in, this is what shows up (in the text field):
No idea how that's happening. I've tried str_replace(), $var[15] = '' and a load of other methods. All are doing the same!
ord()on each character of the string to find out the ascii value.varchar? What kind of DB are you using?