add 4 characters to 32 character string

Posted on 2012-08-29
Last Modified: 2012-08-30
32 character string.
add 4 characters on these positions


adding WXYZ

this is a related question for a smaller string which I thought was correct
Question by:rgb192
    LVL 58

    Expert Comment

    A nonsensical question because even in the previous question you did not say how the string should be added to

    Author Comment


    W place 7
    X place 13
    Y place 23
    Z place 31

    other question was (in my opinion) correct
    LVL 14

    Accepted Solution

    you need to read the PHP documentation on substr() to solve your problem.  If you are inserting 4 characters then you need to take the starting string, break it into the 5 appropriate pieces using a series of substr() and concatenate the 5 substrings and the 4 characters together.  This will get you started. You should be able to complete it and therefore understand what you are doing on your own.

    $old = '0123456W789abXcdefghijkYlmnopqrZstuv';

    $new = substr($old, 0, 7) . 'W' . substr($old, 8, 5) . 'X' ......

    echo $new;
    LVL 107

    Expert Comment

    by:Ray Paseur
    Can you please tell us in plain language why you would want to do this?  I have years of computer science study and work experience and I have never seen anyone with a need for this kind of data manipulation, so it makes me think that there is an underlying question, not yet in evidence here.  Perhaps if we discuss that question we can get you to a better answer than substring concatenation.

    Standing by, ~Ray

    Author Closing Comment

    this worked for me

    thank you

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
    Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now