knightcon_2004 Posted January 19, 2007 Share Posted January 19, 2007 I want to be able to parse a string like in IRC command style posts. eg...[code]/boot username message[/code]The only problem with using explode or split function deliminated by spaces is that the optional message at the end will also contain spaces in it. So is there a way to enter the sections into an array to split the command, the required variables, and the optional message at the end. It could be something like containing the message in inverted commas ""Thanks Link to comment https://forums.phpfreaks.com/topic/34935-irc-style-string-parsing/ Share on other sites More sharing options...
RobinTibbs Posted January 20, 2007 Share Posted January 20, 2007 the 'trim' function could get rid of the spaces and any extra characters if that is part of the problem? hope that helps Link to comment https://forums.phpfreaks.com/topic/34935-irc-style-string-parsing/#findComment-164948 Share on other sites More sharing options...
Destruction Posted January 20, 2007 Share Posted January 20, 2007 Explode has a third parameter which is limit. I'll give an example:[code]<?php$var = '/boot username because i said so';$parts = explode(' ', $var, 3);?>[/code]The above will produce an array of 3 parts maximum, the last part will be everything remaining that wasn't exploded. So, the above would produce:1st part: /boot2nd part: username3rd part: because i said soHope this helps,Dest Link to comment https://forums.phpfreaks.com/topic/34935-irc-style-string-parsing/#findComment-164952 Share on other sites More sharing options...
knightcon_2004 Posted January 21, 2007 Author Share Posted January 21, 2007 Yeah, that's what i've been looking for, thanks destruction.-------------------------------------------------------------------------------------------------------===================================Topic Solved====================================------------------------------------------------------------------------------------------------------- Link to comment https://forums.phpfreaks.com/topic/34935-irc-style-string-parsing/#findComment-165195 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.