arrays - PHP split string into tokens and tags -
i have string needs separated (with php) 2 arrays: tokens , tags.
let's string:
radioed/jj to/to earth/nn and/cc the/dt control/nn room/nn here/rb ./pun
need 2 arrays, so:
$_tokens = array("radioed","to","earth","and","the","control","room","here","."); $_tags = array("jj","to","nn","cc","dt","nn","nn","rb","pun");
this means since each phrase in format: token/tag
need possible. plus, have token/tag combinations might unsafe directly place string (i.e. "/puq, quotation mark " token , puq tag), need able escape these somehow.
can please suggest efficient , fast method of doing this?
thanks!
$sets = explode(' ', $string); foreach ($sets $set) { list($_tokens[], $_tags[]) = explode('/', $set); }
see here in action: http://codepad.viper-7.com/a3zga0
Comments
Post a Comment