0

when using php, i send a value to email via POST method, i want it to add a space, after the 6th character (number in this case) when showing up on the email. So via php, i send it on this way:

ID Number : ".$_POST['idnumber']."

and when i get it on the email, currently is like this:

ID Number : 965128523171363920

So what i'm trying to do is to add a space after the sixth number when it comes to my email, that would look like this:

ID Number : 965128 523171363920

Is this possible on PHP, i'm sorry i'm a newbie on this.. Thank You in Advance

2
  • preg_replace('~^(\d{6})~', '\\1 ', $_POST['idnumber']) Commented Jan 9, 2014 at 2:20
  • Don't forget to validate $_POST (and $_GET and $_COOKIE) variables. Commented Jan 9, 2014 at 2:54

2 Answers 2

1
$first_six = substr($_POST['idnumber'], 0, 6);
$the_rest = substr($_POST['idnumber'], 6);
//Merge the two strings
$final = $first_six.' '.$the_rest;

More info here

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, and everyone else for replying, the Lance's code was very easy and effective.
0

Use substr() to get the parts of the strings you want.

echo sprintf("%s %s", substr($_POST['idnumber'],0, 6), substr($_POST['idnumber'], 6));

See it in action

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.