2010-12-17 68 views
1

基本上我就做一個字符串,它看起來像查找某些文本

#schedule take out trash #in 20

,我需要能夠拉出「拿出垃圾」和「20」和把它們放在他們自己的變量中。可能?

+0

是的,它是可能的。你有什麼嘗試? – 2010-12-17 06:11:55

回答

2

使用preg_match,例如

if (preg_match('/#schedule (.+?) #in (\d+)/', $string, $matches)) { 
    // found matches 
    $instruction = $matches[1]; 
    $time = $matches[2]; 
} 
+0

謝謝。完美的作品。 – 2010-12-17 06:21:44

1

list($task, $delay) = preg_split("/\s?#(\w+)\s?/")

做任何事都應努力在常規格式,除非你需要擔心的人把#在任務名稱