0
我有一个HTML字符串这样如何获得HTML标签之间的值的字符串
<span class="date booking-date">Dec 2, 2015</span><span class="time booking-time">6:36 am</span>
我想2个值Dec 2, 2015
和6:36
(不包括am
)到2个变量与PHP,我应该使用preg_match
要那样做?
我有一个HTML字符串这样如何获得HTML标签之间的值的字符串
<span class="date booking-date">Dec 2, 2015</span><span class="time booking-time">6:36 am</span>
我想2个值Dec 2, 2015
和6:36
(不包括am
)到2个变量与PHP,我应该使用preg_match
要那样做?
而不是使用preg_match
获得独立的值,你可以使用strip_tags
和DateTime对象,如:
$string = '<span class="date booking-date">Dec 2, 2015</span><span class="time booking-time">6:36 am</span>';
$dateTime = new DateTime(strip_tags($string));
var_dump($dateTime->format('Y-m-d H:i:s'));
输出将
string(19) "2015-12-02 06:36:00"
做这样的好处是,你可以操纵然而你想要的日期。
非常感谢! –
是的,请使用preg_match – RamRaider