____________________________________________________ $str = "sleep is good for you. sleep gives you the energy you need to function";
$Nstr = ereg_replace("sleep","coffee",$str); echo $Nstr;
$strLCaseAdage="there's many a slip twixt cup and lip";
echo $strLcaseAdage."<br />";
$strUcaseAdage=strtoupper($strLcaseAdage);
echo $strUcaseAdage."<br />";
____________________________________________________ $str = "sleep is good for you. sleep gives you the energy you need to function";
$Nstr = ereg_replace("sleep","coffee",$str); echo $Nstr;
The browser is using a proportional font so multiple spaces do not take as much room as you would expect. It's not your code, it's the way the browser displays it. To see what I mean use the View|Source option on the browser to confirm the spaces are still there.
If you want multiple spaces to show up as such you need either a fixed font or to use   in place of each space.
Also you seem satisfied modifying your input, which is often the right choice. But don't forget you can also use regular expressions to do nice things like ignore the whitespace, allowing you to compare without the need to either copy your input, or change it.
I just want to make sure that my database isn't filled with spaces and what nots.
Since I'm building a forgot your password feature in my website so I need to compare some of the details.. like mother's name for example. SO I'm concerned whether they put 'Lily W' or ' lily W' or whatever and they won't be able to get their password.
So I'm stripping everything off then comparing them.
It is not the browser with the proportional font, it is HTML that is not whitespace specific. One space or fifty spaces make no difference.
That's why you are pretty free in formatting the HTML using whitespace, tabs, returns, spaces, newlines.
But, don't forget that the data itself (if in a database or within PHP) has the whitespace, eventhough HTML does not display it.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.