Here's my problem:

I have a place in my database for phone numbers as a 10-digit text field. So, when somone enters in their phone number, it goes in as 5555555555.

How do I print it so when it comes out it looks like (555) 555-5555?

Surely there's an easy way to do this, right?

Thanks,

Eric (n00b, but I'm trying)

    Hi, the following code isn't the best - BUT it works.

    <?php

    $string='0123456789';

    echo "(";
    echo $string{0};
    echo $string{1};
    echo $string{2};
    echo ")";
    echo $string{3};
    echo $string{4};
    echo $string{5};
    echo "-";
    echo $string{6};
    echo $string{7};
    echo $string{8};
    echo $string{9};

    ?>

    Simply change the value of $string to whatever variable you pull your phone number with.

    Hope this helps.

      Another way is:

      <?php
      $tele = '1234567890';
      $areacode = substr($tele, 0, 3);
      $pre = substr($tele, 3, 3);
      $suff = substr($tele, 6, 4);
      echo '(' .$areacode. ') ' .$pre. '-' .$suff;
      ?>
      
        Write a Reply...