ballhogjoni Posted January 21, 2008 Share Posted January 21, 2008 Hi, I recieve a response string from my curl script e.g. 'Username:xxxxxxxxxxxxxxx UserID:xxxx' and I want to be able to split it up at the : character and basically put it into a session. Example: $_SESSION['a'] = 'xxxxxxxxxxxxxxx'; $_SESSION['b'] = 'xxxx'; I don't want the session variable to include Username and UserID from the original string. I hope that made since. Link to comment https://forums.phpfreaks.com/topic/87122-solved-split-a-string/ Share on other sites More sharing options...
effigy Posted January 21, 2008 Share Posted January 21, 2008 <pre> <?php $data = 'Username:xxxxxxxxxxxxxxx UserID:xxxx'; list($_SESSION['a'], $_SESSION['b']) = preg_split('/\s*User(?:name|ID):/', $data, 2, PREG_SPLIT_NO_EMPTY); print_r($_SESSION); ?> </pre> Link to comment https://forums.phpfreaks.com/topic/87122-solved-split-a-string/#findComment-445570 Share on other sites More sharing options...
rbrown Posted January 21, 2008 Share Posted January 21, 2008 Another way: $session_a=explode(':',$_SESSION['a']); echo $session_a[1]; do the same for b Link to comment https://forums.phpfreaks.com/topic/87122-solved-split-a-string/#findComment-445571 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.