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
  1. #1
    New Coder
    Join Date
    Feb 2008
    Posts
    97
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Separate one string in two

    Hi all,

    Sure it is a piece of cake, but in my numbness I don't see how to do it ..
    I have the following string “color124.gif” and I want to separate it in two different strings “color” and “124” (124 can be a int) .. How can I do it?

    Thanks a lot in advance!

  • #2
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    PHP Code:
    <?php

    $string  
    "color124.gif";

    $pattern = array("/[a-z]+/""/[1-9]+/");
    $parts = array();

    $i=0;
    foreach (
    $pattern as $val) {
    preg_match ($pattern[$i], $string$match);
    $parts[$i] = $match[0];
    $i++;
    }
    print 
    "Part 1: ".$parts[0];
    print 
    "Part 2: ".$parts[1];

    ?>
    Last edited by matak; 02-26-2008 at 02:56 PM. Reason: removed extra array in match

  • #3
    New Coder
    Join Date
    Feb 2008
    Posts
    97
    Thanks
    0
    Thanked 0 Times in 0 Posts
    gorgeous, thank u very much!


  •  

    Posting Permissions

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