SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Feb 2004
    Location
    Winnipeg Canada
    Posts
    144
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    preg_split instead of split

    Since split is depracated in 5.3 and removed in 6, I am doing a quick check on some scripts I have, in which the developer is long gone and won't be doing any updates.

    Luckily, there are only a few instances of "split" found and I planned on replacing them with preg_split -but it is not working. The scripts work with split (since it is just deprecated in 5.3) but won't work as "preg_split".

    Obviously, I am missing something in the difference between the two - would appreciate being pointed in the right direction.

    Here are two example of existing SPLIT uses, I would like to change to preg_split.

    FIRST:
    Code:
    split("[\/]", $path);
    
    if I change this to the following it works, 
    explode("\\", $path);
    
    but I would like to know why preg_split doesn't work.
    SECOND:
    Code:
    split('[\\/]', $file);

  2. #2
    SitePoint Zealot
    Join Date
    Feb 2004
    Location
    Winnipeg Canada
    Posts
    144
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I found the following solution and it appears to work.
    Code:
    split("[\/]", $path);
    should become
    preg_split("_[\\\\/]_",$path);
    The same preg_split regex works with both scenerios.

    If anybody has a better solution, of if they know of a reason this solution is not good - please let me know!


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
  •