#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Colombo, Western, Sri Lanka
    Posts
    41
    Rep Power
    14
    This is what I need to do.

    I have a string returned by a query.

    I want to trim the 1st 4 characters of this string and thereafter trim the 1st 3 characters of the result (of 1st trim) and then again trim the result of the 2nd trim so that I retain the 1st 2 characters only of the 2nd trim.

    eg:

    string = abcf00101XL

    1st trim =(abcf) : result= 00101XL

    2nd trim =(001) : result = 01XL

    3rd trim =(XL) : result = 01

    The final result I need is = 01


    I hope the example I've given is clear.

    Please note that there could also be strings of like abcf00101s.

    Please help if you any ideas on how I could do this. Thanks.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Location
    Alkmaar, The Netherlands
    Posts
    123
    Rep Power
    14
    It looks like you always want to use the 8th an 9th character of the string. Why don't you use the substring() function:

    $string = "abcd00101XL";

    $result = substr($string,7,8);

    ------------------
    Good luck,
    Bas

    ------------------
    E-mail me at: b.vandermeijden@pecoma.nl
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2000
    Posts
    79
    Rep Power
    15
    I think it should be..
    $result = substr($string, 7, 2);

    Basil
  6. #4
  7. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15

    <<
    $string = "abcd00101XL";
    $result = substr($string,7,8);
    >>



    It can be also the following...(this only for your final result)...

    $string = "abcd00101XL";
    $result = substr($string,strlen($string)-2);
    //cut from the second last...



    ------------------
    SR -
    webshiju.com
    www.jobxyz.com-IT Career Portal
    ezipindia.com--WebStudio


    "The fear of the LORD is the beginning of knowledge..."

Similar Threads

  1. Extended characters (&# codes) don't work in FPDF...
    By 80sDweeb in forum PHP Development
    Replies: 0
    Last Post: January 2nd, 2004, 12:44 PM
  2. Advice on reversing order of characters within a string?
    By FriscoKid in forum C Programming
    Replies: 5
    Last Post: November 13th, 2003, 08:13 AM
  3. Escape characters in a move command?
    By Donboy in forum UNIX Help
    Replies: 1
    Last Post: September 24th, 2003, 03:58 PM
  4. Is there a way to use literal '{' brace characters in php?
    By sstringer in forum PHP Development
    Replies: 8
    Last Post: March 8th, 2003, 03:58 PM
  5. dealing with repeating characters or limiting word lengths
    By craig.stewart in forum PHP Development
    Replies: 1
    Last Post: March 15th, 2002, 12:02 PM

IMN logo majestic logo threadwatch logo seochat tools logo