View Full Version : How to remove data from a variable before passing on

04-30-2009, 12:27 AM
I have a form on my site that goes like this:

For Field, user enters EITHER 1tt or 1

I want my php to check if they have entered 1tt or 1 and if tt is present remove the tt before proceeding and if tt exists then remove tt but keep the first number that they entered.

The additional letter will always be the same so I do not need to check a-z, just tt. I know how to check for it, would just like to know how to split the variable / remove the letters from it.

Any ideas?

04-30-2009, 12:50 AM
Something like this I suppose?

$stringtt = "1tt";

if(stripos($stringtt, 'tt')){ // uses stripos since it case-insensitive for tt or TT
echo 'tt found, should we abort? <br/>';
//replace tt with ""
$new_string = str_ireplace("tt", "", $stringtt);
echo 'The new string is: ' . $new_string;