Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: String Mystery

  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    553
    Thanks
    0
    Thanked 0 Times in 0 Posts

    String Mystery

    I have a string $element="xxxxxx". I wish to change the second character from 'x' to 'p'. Seems like this should work:
    substr_replace($element,"P",1,1);

    But this makes no change at all. Why not?

    G

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The new string value is returned instead of working directly on the string.

    PHP Code:
    $element "xxxxxx"
    $element substr_replace($element"P"11); 
    echo 
    $element

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Posts
    553
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Right... Thanks!

    G


  •  

    Posting Permissions

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