Reputation: 3642
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 them in their own variables. Possible?
Upvotes: 1
Views: 774
Reputation: 27916
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
Upvotes: 1
Reputation: 165059
Use preg_match
, for example
if (preg_match('/#schedule (.+?) #in (\d+)/', $string, $matches)) {
// found matches
$instruction = $matches[1];
$time = $matches[2];
}
Upvotes: 2