SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: complex explode

  1. #1
    SitePoint Wizard
    Join Date
    Jan 2005
    Location
    blahblahblah
    Posts
    1,447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    complex explode

    Hi,
    I've been trying for two hours to do the following. It's probably incredibly simple but I must be too tired... Can someone help?

    PHP Code:
    $string 123+456-789*123/456
    //should be turned into:

    [0] => 123
    [1] => +
    [
    2] => 456
    [3] => -
    [
    4] => 789
    [5] => *
    [
    6] => 123
    [7] => /
    [
    8] => 456 

  2. #2
    SitePoint Guru whisher's Avatar
    Join Date
    May 2006
    Location
    Kakiland
    Posts
    732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this

    PHP Code:
    $string '123+456-789*123/456';
    preg_match_all('#(\d+)(\+)(\d+)(\-)(\d+)(\*)(\d+)(\/)(\d+)#'$string$matches);
    array_shift($matches);
    var_dump($matches); 

  3. #3
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $r preg_split('%([-+*/])%''123+456-789*123/456', -1PREG_SPLIT_DELIM_CAPTURE);
    var_dump$r ); 
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  4. #4
    SitePoint Guru whisher's Avatar
    Join Date
    May 2006
    Location
    Kakiland
    Posts
    732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I did my best

    COOL


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
  •