yanjchan Posted March 22, 2009 Share Posted March 22, 2009 Ok, I have my string here: cb9f35facc807b87b3024726e6ffe4ff0382b6e54f84f082c4292fb8251378c3:edba6720b115c4d20fb78b4371d84d3783b1094fac000fc886d865bc1eb9572a@76.103.101.157 That is separated by : and @. I get the string from the cookie using the PHP $_COOKIE['blah'], which works fine. Then, when I try to split it using: $raw = $_COOKIE['blah']; $blah = split('[:@]', $raw); echo "$blah[0]<br />"; echo "$blah[1]<br />"; echo "$blah[2]<br />"; Only $blah[0] returns a variable, which is the entire string. I'm sorry if I'm making a stupid mistake, as I think I've mentioned before, I'm pretty new to PHP. Thanks! Link to comment https://forums.phpfreaks.com/topic/150621-php-split-problems/ Share on other sites More sharing options...
GingerRobot Posted March 22, 2009 Share Posted March 22, 2009 You need to separate by the @ symbol or the : symbol. For that you need a pipe(|): $blah = split('[:|@]', $raw); Though i don't see why you're not delimiting by the same character in both instances? Link to comment https://forums.phpfreaks.com/topic/150621-php-split-problems/#findComment-791197 Share on other sites More sharing options...
DarkWater Posted March 22, 2009 Share Posted March 22, 2009 I'm fairly sure he didn't realize he needs delimiters and got really lucky since he used a character class as his whole regex. [ ] counts as a delimiter pair, so it didn't throw an error. Try this instead: $blah = split('/[:@]/', $raw); Link to comment https://forums.phpfreaks.com/topic/150621-php-split-problems/#findComment-791201 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.