SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict
    Join Date
    Mar 2011
    Location
    Manchester, UK
    Posts
    226
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Check Value & Edit It

    Hi Guys,

    I have a form which people submit how ever i need to know how to do the following please. People enter their mobile number in the UK so it will be something like 07812345678

    Now i need it so the consumer enters it in this format

    +447812345678

    (Country Code and then the number without the first 0)

    How do i code it so when they enter their number i adds 44 at the beginning and removes the first 0 in the variable?

    Any help would be good.

    Thanks
    You're Help Does Not Go Unnoticed, I have So Far Donated 25 GBP
    To Cancer Research UK As A Thank You To All The SitePoint
    Members That Have Helped Me In The PHP Forum Thank You!

  2. #2
    SitePoint Enthusiast
    Join Date
    Jan 2009
    Location
    Michigan
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You'll have to check first to make sure that the first character of the string is a "0." if it is then you could use str_replace(); to replace it with the +44 (or other country code)
    These links may help:

    strpos()
    str_replace()

  3. #3
    SitePoint Addict
    Join Date
    Mar 2011
    Location
    Manchester, UK
    Posts
    226
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I need some help please, I've managed to code it but for some reason its not working correctly.

    PHP Code:
    $mobileno=$_POST['mobileno'];
    $findme '07';
    $pos strpos($mobileno$findme);

    // Note our use of ===.  Simply == would not work as expected
    // because the position of 'a' was the 0th (first) character.
    if ($pos==='0') {
        echo 
    "Its At The Beginning!";
    } else {
            echo 
    "Wrong";

    If i enter a number that has 07 at the beginning then it still echos Wrong. What have i done wrong?

    Thanks
    You're Help Does Not Go Unnoticed, I have So Far Donated 25 GBP
    To Cancer Research UK As A Thank You To All The SitePoint
    Members That Have Helped Me In The PHP Forum Thank You!

  4. #4
    SitePoint Enthusiast
    Join Date
    Jan 2009
    Location
    Michigan
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're almost there!

    Change your if statement to:

    PHP Code:

    if ($pos == 0) {
        echo 
    "Its At The Beginning!";
    } else {
            echo 
    "Wrong";

    and it should work for you. We do this because the strpos() returns an integer and not a string.

    hope this helps!

  5. #5
    SitePoint Addict
    Join Date
    Mar 2011
    Location
    Manchester, UK
    Posts
    226
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you MainStWebGuy! It didnt work at first but i changed it to '===' instead of '==' and it works fine now

    Can you take a look at my other thread please.
    You're Help Does Not Go Unnoticed, I have So Far Donated 25 GBP
    To Cancer Research UK As A Thank You To All The SitePoint
    Members That Have Helped Me In The PHP Forum Thank You!

  6. #6
    SitePoint Enthusiast
    Join Date
    Jan 2009
    Location
    Michigan
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    awesome, and yeah i'll take a look. What's the link?

  7. #7
    SitePoint Addict
    Join Date
    Mar 2011
    Location
    Manchester, UK
    Posts
    226
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're Help Does Not Go Unnoticed, I have So Far Donated 25 GBP
    To Cancer Research UK As A Thank You To All The SitePoint
    Members That Have Helped Me In The PHP Forum Thank You!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •