Basically I'll be having a string that looks like
#schedule take out trash #in 20
and I need to be able to pull out "take out trash" and "20" and put th开发者_如何学编程em in their own variables. Possible?
Use preg_match
, for example
if (preg_match('/#schedule (.+?) #in (\d+)/', $string, $matches)) {
// found matches
$instruction = $matches[1];
$time = $matches[2];
}
list($task, $delay) = preg_split("/\s?#(\w+)\s?/")
should work for anything in that general format unless you need to worry about people putting #
in the task name
精彩评论