0

im triying to add dash in the phone numbers when added, the phone numbers are added complete without spaces. like: 1234567890, and i want the output to be:

123-456-7890

Depending on where the number is from it will change, for ex.:

  • Italy is: +391234567890 (+39-123-456-7890)

  • Spain is: +34123456789 (+34-123-45-67-89)

and so on.

this is the code im triying to add it to:

        <div class="btn-group btn-group-sm" role="group" aria-label="Extra-small button group">
        <a class="client_copy btn btn-gold" 

           data-client-name="<?php echo $emp['client_name']; ?>" 
           data-Client-email="<?php echo $emp['id_clients']; ?>" 
           data-client-phone="<?php echo $emp['phone_no']; ?>"
           data-client-id="<?php echo $emp['ID']; ?>"
           data-client-group="<?php echo $emp['group_name']; ?>"
           data-client-city="<?php echo '$' . $emp['myprice']; ?>"
           data-client-paymentmethod="<?php echo $emp['payment_method_name']; ?>"
           data-client-paymentvia="<?php echo $emp['payment_via_name']; ?>"
           data-client-paymentdetail="<?php echo $emp['payment_detail']; ?>"
           data-client-paymentdate="<?php echo $emp['payment_date']; ?>"
           data-client-customprice="<?php echo $emp['custom_price']; ?>"

           href="#modalCopyClient"><i class="fa  fa-files-o"></i></a>

So, the phone part is:

data-client-phone="<?php echo $emp['phone_no']; ?>"

i tried a couple solutions posted here but i coulndt make it work

one of them was to add:

echo '('.substr($data, 0, 3).') '.substr($data, 3, 3).'-'.substr($data,6);

that may be the solution but it didnt work for me, i ended having an error

i add it this way:

data-client-phone="<?php echo '('.substr($data, 0, 3).') '.substr($data, 3, 3).'-'.substr($data,6); $emp['phone_no']; ?>"

and had this error:

Error

i know the error might be obvious but i just dont know that much about coding. sorry.

thanks!

CD 20
  • 11
  • 2
  • You need to post what have you tried so far – Spoody Oct 13 '17 at 18:47
  • i tried adding: echo '('.substr($data, 0, 3).') '.substr($data, 3, 3).'-'.substr($data,6); i dont know very much about coding, im just triying to fix that – CD 20 Oct 13 '17 at 18:52
  • Post your code in the question not as a comment so it is easy to read – Spoody Oct 13 '17 at 18:53
  • done, sorry and thanks – CD 20 Oct 13 '17 at 18:55
  • @CD20 We are not a code writing service. We can help you with specific problems but are not going to write a full implementation. Also you are giving two examples for countries. How do you expect us to know which country is implemented which way? – Ivar Oct 13 '17 at 18:55
  • So, can you tell me the error you ended having? – Spoody Oct 13 '17 at 18:56
  • @Ivar i dont want a full implementation, im giving the two country examples so you know that is not a single format, if someone can help with letting me know how to output the dashes the rest is my work. thanks – CD 20 Oct 13 '17 at 18:57
  • I see you tried the solution in [this question](https://stackoverflow.com/a/2089949). What doesn't work for you? – Ivar Oct 13 '17 at 19:01

0 Answers0