Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Replace part of string at particular position

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 106
    Comment on it

    You can easily replace a part of string at a given postion of a substring with the help of string function known as substr_replace

    $string2="abcdefghijklmnop";
    
    if (strpos($string2,"abcd")!==false)
    
    {
    
    $pos=strpos("abcd",$string2);
    
    $len=strlen("abcd");
    
    $newstring=substr_replace($string2,"ABCD",$pos,$len);
    
    }
    
    echo "<br>";
    
    print_r($string2);
    
    echo "
    "; print_r($newstring);

    So the output will become:

    abcdefghijklmnop

    ABCDefghijklmnop

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: