SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: Splitting "?"

  1. #1
    SitePoint Guru GamerZ's Avatar
    Join Date
    Nov 2001
    Location
    Singapore
    Posts
    617
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Splitting "?"

    Hmm, whenever I try to split a "?" i get an error.

    Here is the code
    PHP Code:
    $location split("?"$location); 
    Error
    Warning: split() [function.split]: REG_BADRPT:repetition-operator operand invalid

  2. #2
    SitePoint Addict
    Join Date
    May 2001
    Location
    hong kong
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    use explode instead as I have met similar errer before and still don't know the reason yet..
    Is it the vesion of php issue??

  3. #3
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The first argument to split() is a regular expression.
    Code:
    $location = split("/\?/", $location);

  4. #4
    SitePoint Guru GamerZ's Avatar
    Join Date
    Nov 2001
    Location
    Singapore
    Posts
    617
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by redemption
    The first argument to split() is a regular expression.
    Code:
    $location = split("/\?/", $location);
    okie thanks, i think taht will do the trick =D

  5. #5
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    explode() would be more efficient (not by much though) if you're an efficiency freak. I wouldn't bother

    By any chance are you splitting a query string?

    Nice site you have there btw... Still at SP or going to enlist? (or worse - enlisted! )

  6. #6
    SitePoint Guru
    Join Date
    Oct 2001
    Posts
    656
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    explode() would be more efficient (not by much though) if you're an efficiency freak. I wouldn't bother
    If you use preg_split() for this, you are using the wrong function for the wrong thing. You should only use the preg_() functions if you need to utilize regular expressions. For simple string replacing and splitting always use functions such as str_replace() and explode().

    Don't get yourself into the bad habit of using the preg_*() functions when not needed. The performance penalty may not be much in smaller scripts, but in larger scripts it can definitely make a difference.

  7. #7
    SitePoint Guru GamerZ's Avatar
    Join Date
    Nov 2001
    Location
    Singapore
    Posts
    617
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by redemption
    explode() would be more efficient (not by much though) if you're an efficiency freak. I wouldn't bother

    By any chance are you splitting a query string?

    Nice site you have there btw... Still at SP or going to enlist? (or worse - enlisted! )
    yap i am going an online user thingy, so it will insert the location of the user is at. Then by splitting the query string i can determine where the user is at. my site contents are all in the form of site.php?section=about&content=life

    hehe =D


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
  •