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 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jan 2004
    Location
    Des Moines, Iowa
    Posts
    219
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Programmer's Block - Ripping out part of a string

    Good morning, afternoon and evening!

    I'm experiencing the dreaded programmer's block.

    I have a string $row['isbn'].

    It contains a number like: 0830814574

    I want to catch only these digits of the string: 0830814574.

    I cannot for the life of me remember which PHP function assists me in this.

    Any help would be greatly appreciated. :-)

    Thanks,
    Rich
    Rich S. Wyatt
    D3 Web Creations

  • #2
    Regular Coder
    Join Date
    Mar 2004
    Posts
    115
    Thanks
    0
    Thanked 0 Times in 0 Posts
    if the numbers are in the same position then you could use substr()

    http://uk.php.net/manual/en/function.substr.php

  • #3
    Regular Coder
    Join Date
    Jan 2004
    Location
    Des Moines, Iowa
    Posts
    219
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Goooooooood grief...

    Thank the Lord for forums... I've only used substr() hundreds of times.. I guess I know what writers go through now, suddenly having no idea what to write.

    Thanks Sydney!

    Rich
    Rich S. Wyatt
    D3 Web Creations

  • #4
    Regular Coder
    Join Date
    Mar 2004
    Posts
    115
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you could also use substring() in your mysql query to only retrive the substring you want

    http://dev.mysql.com/doc/mysql/en/String_functions.html

  • #5
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    What if the Characters are not in the same position

    I have a field that has :
    SMTP:{email@email.com}blahblahblah
    I need the characters in between the {}, no matter what the length is.
    I can always tell the starting position, but cannot tell the ending }

  • #6
    Mega-ultimate member
    Join Date
    Jun 2002
    Location
    Winona, MN - The land of 10,000 lakes
    Posts
    1,855
    Thanks
    1
    Thanked 45 Times in 42 Posts
    probably be best off with preg_match() in that case...

    Something like...

    Code:
    $str = "SMTP:{email@email.com}blahblahblah";
    $matches = preg_match_all("/^SMTP:\{(.*?)\}\w*/",$str);
    print_r($matches); //shows what matched.
    print $matches[1]; //should be the matched string.
    Should to the trick. Not tested though.


  •  

    Posting Permissions

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