Is it possible to check the fields?

Asked

Viewed 54 times

3

My problem is, "I have one array which stores data from duas combos. In a combo i add "P" and then the entered value. Ex: P111111111. And the next I add at the beginning "S" and it gets S11111111. But in my bank table I have separate fields for the P and to the S, and so I wonder if you have how to make a insert to check if the first letter is P or S, in order to be able to insert in their due fields!

2 answers

4


yes... a way to do this in php:

$str = $_ POST ou GET['sua variavel']

$posição1 = str_split($str,1);

switch ($posição1) {
    case 'P': //Faz o que voce quer;
    break;
    case 'S': //Faz o que voce quer;
    break;
    default: break;
}
  • Thank you very much @ Marcelobonifazio, this is exactly what I needed!

2

Another way to extract the first character from a string is to use replace

$char = substr($str, 0, 1); //copia um caracter da posição zero

or pass variable zero index

$char = $str[0];
  • Very good your answer @lost. Along with the one that @ Marcelobonifazio gave, I can do exactly what I need to do!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.