设置一周中每天的开放和关闭时间

时间:2016-03-23 10:24:24

标签: php xml

我有以下代码来检查开始和结束时间,它运行正常。

// MyClass has an abstract method named "AbstractMethod"
MyClass class_object = new MyClass()
{
   @Override
   public void AbstractMethod()
   {
     // Do something here
   }
};
class_object.AbstractMethod();

我想要实现的是从xml文件中获取时间,但它无法正常工作

// Set open and closing time for each day of the week
if ($weekday == "Monday") {
$open_from = "17:00";
$open_to = "21:45";
}

我在另一个参数中使用此代码,它工作正常。

// Set open and closing time for each day of the week
if ($weekday == "Monday") {
$open_from = "<?php echo $mondayopen->nodeValue  ?>";
$open_to = "<?php echo $mondayclosed->nodeValue  ?>";
}

2 个答案:

答案 0 :(得分:2)

您可以直接访问$modayopen$mondayclose,无需回复:

// Set open and closing time for each day of the week
if ($weekday == "Monday") {
  $open_from = $mondayopen->nodeValue;
  $open_to = $mondayclosed->nodeValue;
}

答案 1 :(得分:0)

你的php代码应该是这样的

 if ($weekday == "Monday") {
    $open_from = $mondayopen->nodeValue;
    $open_to = $mondayclosed->nodeValue;
    }
//(or)
    if ($weekday == "Monday") {
    $open_from = '"'.$mondayopen->nodeValue.'"';
    $open_to = '"'.$mondayclosed->nodeValue.'"';
    }