问题
Hi I need to filter the xml that was given to me base on the following conditions ex. category needs to be Transportation, package needs to be Good and the last one item needs to have been publish today only.
here is the sample xml
<item>
<category>Transportaion</category>
<package>Good</package>
<date>2018-04-17 17:10:46</date>
<title>Item sample 1</title>
<description>This is a sample</description>
</item>
<item>
<category>Wanted</category>
<package>Good</package>
<date>2018-04-17 18:03:46</date>
<title>Item sample 2</title>
<description>This is a sample</description>
</item>
<item>
<category>For sale</category>
<package>Better</package>
<date>2018-04-16 14:03:46</date>
<title>Item sample 3</title>
<description>This is a sample</description>
</item>
I was able to do the 1st two conditions but I'm clueless about the the last condition Include items published today
here is the code I used
$data= simplexml_load_file("easy2.xml");
$today= date('Y-m-d');
foreach ($data->item as $item)
{
if ($item->category == 'Transportaion' && $item->package == 'Good' && $item->date == '$today')
{
echo "Title: " . $item->title . "<br>";
echo "Category: " . $item->category . "<br>";
}
}
can someone please advice, many thanks
来源:https://stackoverflow.com/questions/49900752/simplexml-conditional