SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist perpetual_dream's Avatar
    Join Date
    Nov 2005
    Location
    Jerusalem
    Posts
    542
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    string split question

    Hello,

    I have a string in the form 123456789-letters-letters

    How can I take the 1st portion of the string which just includes the numbers and how can i take the 1st part if the situation was in the vice versa letters-letters-1234567489?

    Thanks
    Tanzeelnet - Best arabic downloadsite
    Linux Hosting |Free Downloads |

  2. #2
    WebAmoeba mythix's Avatar
    Join Date
    Aug 2002
    Location
    here
    Posts
    578
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if its always going to be in one of those formats (no numbers in amongst the letters) you can use this:

    PHP Code:
    if ( preg_match'\([\d]+)\' , $myString, $array) )
    {
        echo $array[0];

    http://uk.php.net/manual/en/function.preg-match.php
    Laws are like sausages. You have much more respect for them if you haven't actually seen how they're made.

    http://www.webamoeba.co.uk

  3. #3
    An average geek earl-grey's Avatar
    Join Date
    Mar 2005
    Location
    Ukraine
    Posts
    1,403
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or using simple explode.
    First case:
    PHP Code:
    $items explode('-'$string);
    echo 
    $items[0]; 
    Second case:
    PHP Code:
    $items explode('-'$string);
    echo 
    $items[2]; 

  4. #4
    SitePoint Evangelist perpetual_dream's Avatar
    Join Date
    Nov 2005
    Location
    Jerusalem
    Posts
    542
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry didnt look at the explode function reply it works gr8
    Last edited by perpetual_dream; Dec 15, 2006 at 10:47. Reason: found the solution
    Tanzeelnet - Best arabic downloadsite
    Linux Hosting |Free Downloads |


Bookmarks

Posting Permissions

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