0

How do I add spaces to input in the data?

Example:

$request->PoliceNo= B123A

Must be in database = B 123 A

Cookie
  • 87
  • 1
  • 2
  • 11

1 Answers1

0

You can use preg_replace. stated at Regex: Add space if letter is adjacent to a number

$test= 'B123A';
$request->PoliceNo= preg_replace('/(?<=[a-z])(?=\d)|(?<=\d)(?=[a-z])/i', ' ', $test);
Kenneth
  • 2,813
  • 3
  • 22
  • 46