我如何获取 Html 中的元素名称
How can i take the element name inside the Html
如何从 html 元素 2018-06-14T03:00:00.000Z 中找到 UTC 日期格式。我是 php 的新人,所以我不知道如何获取它。
<div class="fi-mu__info__datetime" data-utcdate="2018-06-14T03:00:00.000Z">
14 Jun 2018 - 18:00
<span class="fi-mu__info__localtime">Local time</span>
</div>
使用 Carbon 解析 php 中的日期 https://github.com/briannesbitt/carbon
Carbon::parse('2018-06-14T03:00:00.000Z')->toDateTimeString();
您可以使用 find 来获取带有类名 fi-mu__info__datetime
的 div,然后获取 data-utcdate
:
$data = <<<DATA
<div class="fi-mu__info__datetime" data-utcdate="2018-06-14T03:00:00.000Z">
14 Jun 2018 - 18:00
<span class="fi-mu__info__localtime">Local time</span>
</div>
DATA;
$html = str_get_html($data);
foreach($html->find('div[class=fi-mu__info__datetime]') as $element){
if ($element->hasAttribute("data-utcdate")) {
echo $element->{"data-utcdate"} . '<br>';
}
}
如果您只想要第一个,您可以使用:
echo $html->find('div[class=fi-mu__info__datetime]', 0)->{"data-utcdate"};
如何从 html 元素 2018-06-14T03:00:00.000Z 中找到 UTC 日期格式。我是 php 的新人,所以我不知道如何获取它。
<div class="fi-mu__info__datetime" data-utcdate="2018-06-14T03:00:00.000Z">
14 Jun 2018 - 18:00
<span class="fi-mu__info__localtime">Local time</span>
</div>
使用 Carbon 解析 php 中的日期 https://github.com/briannesbitt/carbon
Carbon::parse('2018-06-14T03:00:00.000Z')->toDateTimeString();
您可以使用 find 来获取带有类名 fi-mu__info__datetime
的 div,然后获取 data-utcdate
:
$data = <<<DATA
<div class="fi-mu__info__datetime" data-utcdate="2018-06-14T03:00:00.000Z">
14 Jun 2018 - 18:00
<span class="fi-mu__info__localtime">Local time</span>
</div>
DATA;
$html = str_get_html($data);
foreach($html->find('div[class=fi-mu__info__datetime]') as $element){
if ($element->hasAttribute("data-utcdate")) {
echo $element->{"data-utcdate"} . '<br>';
}
}
如果您只想要第一个,您可以使用:
echo $html->find('div[class=fi-mu__info__datetime]', 0)->{"data-utcdate"};