Function to insert dash after three characters in a string?
html, php
Solution
$string = "123456";
$insertion = "-";
$index = 3;
$result = substr_replace($string, $insertion, $index, 0);
echo $result;
Problem
I have a form in the input=text the user enters a number like 123456 i want to change this to 123-456 How can I put a dash after a certain numbers of characters? I tried many functions but all of them wants to change or relapse a character and i don't want to change any thing i just want to insert a dash - after three characters in the string. thank you. this is the code that takes the number from the user i want to put this number in a function that insert the dash after three character in the sting inserted buy the user ``` <tr> <td> <small>RIG CHARGE:</small> </td> <td> <input type="text" name="rch" value="<?php echo $objWorksheet->getCellByColumnAndRow(6, 21)->getValue(); ?>"> </td> </tr> ```