0

I'm trying to add a space between any numbers that are passed over. Basically if $var2 was 1028 I want it to add a space so that it becomes 1 0 2 8. I only want it to add it for numerals though and not letters. I only need it to do it on var2-var5 and nothing above that. Any help is greatly appreciated! Thanks!

$apikey = $_GET['apikey'];
$campaign = $_GET['campaign'];
$phone = $_GET['number'];
$delay = $_GET['delay'];
$name = $_GET['var1'];
$var2 = $_GET['var2'];
$var3 = $_GET['var3'];
$var4 = $_GET['var4'];
$var5 = $_GET['var5'];
3
  • 1
    Do you have anything that you have started that isn't working? Commented Jul 6, 2010 at 21:57
  • What does "passed over" here mean? Commented Jul 6, 2010 at 21:57
  • It works right now, but I am basically using this for text to speech. When it's passed over as 1028 it says one-thousand-twenty-eight when I want it to say one-zero-two-eight. What I mean from passed over is on form submit, it gets from the form fields. Commented Jul 6, 2010 at 22:00

3 Answers 3

3
$var2 = implode(' ',str_split($_GET['var2']));
Sign up to request clarification or add additional context in comments.

2 Comments

We'd still have to check that var2 is an integer, though.
That would still need to be checked anyway, irrespective of the method used to split the characters.
0
for ($i = 2; $i <= 5; $i++)
{
    $val = $_GET["var" . $i];
    $pattern = '/\d/g';
    $replacement = '${1} ';
    $newVal = preg_replace(pattern, replacement, $val);
}

Comments

0

Here's a quick function which will make your life a lot easier.

function preg_add( $content, $regex, $replace = '${1}' ) {
   return trim( preg_replace( $content, $regex, $replace ) );
}

To use it you simply do; $var2 = preg_add( $var2, '/([0-9])/', '${1} ' );

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.