SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Not Working

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

    Not Working

    PHP Code:
    $mobileno=$_POST['mobileno'];
    $var $mobileno;
    substr_replace($var'+44'00); 
    Hi Guys,

    Can anyone tell me why the above code doesn't seem to be working, it doesn't seem to be placing +44 at the beginning of $var and instead when the data is added to my database its without the +44.

    Any help would be great.

    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 Addict
    Join Date
    Mar 2011
    Location
    Manchester, UK
    Posts
    226
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've managed to fix this myself by doing the following:

    PHP Code:
    $mobile2 substr_replace($var'+44'00); 
    But how do i go about removing the forth digital in the variable. For example lets say the variable = '+441234567890'

    How do i go about removing the forth value (1) from the variable?

    Any help would be great.

    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!

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2009
    Location
    Michigan
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is a quick "stab" at it, but this may work for you:

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

        if(
    $pos === 0)
        {
            
    $replace $substr($mobileno,0,2);
            
    $newMobile=str_replace($replace"+44",$mobileno);
        }
    echo 
    $newMobile
    You may want to try making $mobileno = to a number with "07" occurring more than once to make sure that only the first occurrence is replaced.

  4. #4
    SitePoint Enthusiast
    Join Date
    Jan 2009
    Location
    Michigan
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Adwarm,

    Just out of curiosity, what kind of project are you working on? Seems cool.

  5. #5
    SitePoint Enthusiast
    Join Date
    Jan 2009
    Location
    Michigan
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah that doesn't work if there is more than one occurrence of "07" try this...

    PHP Code:
    $newMobile substr_replace($mobileno,"+44",0,2); 


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
  •