Jump to content

IRC-Style String Parsing


knightcon_2004

Recommended Posts

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

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: /boot
2nd part: username
3rd part: because i said so

Hope this helps,

Dest
Yeah, that's what i've been looking for, thanks destruction.

-------------------------------------------------------------------------------------------------------
===================================Topic Solved====================================
-------------------------------------------------------------------------------------------------------

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.