CodeIgniter Forums
Input 4 first digit from column A to column B - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Input 4 first digit from column A to column B (/showthread.php?tid=72571)



Input 4 first digit from column A to column B - kelapamuda - 01-07-2019

Hello everybody.
This is simple, i had goggle but havent find result that suit me.
What I want is something like this. The column A is A_number, and column B is B_number.
So I want this condition : for example when user type input 123456789 into column A, the column B automatically filled with 1234
How to do this automatically?


RE: Input 4 first digit from column A to column B - Zigi84 - 01-07-2019

If i understood properly what you meant, here is the solution with native js:

http://jsfiddle.net/y3whbn4o/1/


RE: Input 4 first digit from column A to column B - kelapamuda - 01-08-2019

Is it possible to do that using php only(without js)?


RE: Input 4 first digit from column A to column B - Codinglander - 01-09-2019

PHP Code:
string substr string $string int $start [, int $length ] ) 
try this...


RE: Input 4 first digit from column A to column B - Pertti - 01-09-2019

So you want to access first 4 digits, regardless of what the number is?

Could probably get away with using string functions and literally get first 4 characters out of the string.

PHP Code:
$a 123486868686868;
$aString strval($a);
$b substr($aString04); 

All POST data comes in as string anyway, and PHP is quite good at converting types in and out as it is, but I added extra step in there just to point out string conversion.