我有文件,我需要以BEGIN:VEVENT
开始和以END:VEVENT
结尾的所有部分,我需要所有包含数组中所有这些部分的字符串,我在字符串下面
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
CALSCALE:GREGORIAN
BEGIN:VEVENT
LOCATION:Test Location
DESCRIPTION:Test Description
DTSTART:20190507T185657Z
DTEND:20190507T185657Z
SUMMARY:Test Summary
URL:http://xxxxxxxxx
DTSTAMP:20190507T185657Z
UID:5cdaa1cd6c3c3
END:VEVENT
BEGIN:VEVENT
LOCATION:Test Location
DESCRIPTION:Test Description
DTSTART:20190508T185657Z
DTEND:20190508T185657Z
SUMMARY:Test Summary
URL:http://xxxxxxxxx
DTSTAMP:20190508T185657Z
UID:5cdaa1cd6c3cc
END:VEVENT
END:VCALENDAR
我需要数组中的这2个部分
BEGIN:VEVENT
LOCATION:Test Location
DESCRIPTION:Test Description
DTSTART:20190507T185657Z
DTEND:20190507T185657Z
SUMMARY:Test Summary
URL:http://xxxxxxxxx
DTSTAMP:20190507T185657Z
UID:5cdaa1cd6c3c3
END:VEVENT
BEGIN:VEVENT
LOCATION:Test Location
DESCRIPTION:Test Description
DTSTART:20190508T185657Z
DTEND:20190508T185657Z
SUMMARY:Test Summary
URL:http://xxxxxxx
DTSTAMP:20190508T185657Z
UID:5cdaa1cd6c3cc
END:VEVENT
任何人都可以帮助我,我们如何获得呢?
答案 0 :(得分:1)
使用.*
修饰符(?
匹配所有字符,包括换行符)在开始和结束定界符之间捕获所有s
非贪婪.
:
$text = file_get_contents('/path/to/file.txt');
preg_match_all('/BEGIN:VEVENT.*?END:VEVENT/s', $text, $result);
print_r($result[0]);