我的PHP存在问题,我试图将小时数转换为格式,例如:我有时间晚上9点,我将它们转换为格式20140501210000。
当我尝试将时间转换为格式时,我收到警告,它希望参数2为字符串。错误是跳到这一行:$ex = explode(" ",$string);
这是时间的输入:
9:00 PM 9:30 PM 9:00 PM 9:00 PM 9:00 PM 9:00 PM 9:30 PM
以下是我遇到的错误:
Warning: explode() expects parameter 2 to be string, object given in /home/myusername/public_html/work_on_this.php on line 8
Warning: explode() expects parameter 2 to be string, object given in /home/myusername/public_html/work_on_this.php on line 8
Warning: strtotime() expects parameter 1 to be string, object given in /home/myusername/public_html/work_on_this.php on line 78
19700101010000
Warning: explode() expects parameter 2 to be string, object given in /home/myusername/public_html/work_on_this.php on line 8
Warning: explode() expects parameter 2 to be string, object given in /home/myusername/public_html/work_on_this.php on line 8
Warning: strtotime() expects parameter 1 to be string, object given in /home/myusername/public_html/work_on_this.php on line 78
19700101010000
这是PHP:
<?php
ini_set('max_execution_time', 300);
$errmsg_arr = array();
$errflag = false;
function getState($string)
{
$ex = explode(" ",$string);
return $ex[1];
}
$xml .= '<?xml version="1.0" encoding="UTF-8" ?>';
$xml .= '
<tv generator-info-name="www.mysite.com/xmltv">';
$baseUrl = file_get_contents('http://www.mysite.com/get-listing.php');
$domdoc = new DOMDocument();
$domdoc->strictErrorChecking = false;
$domdoc->recover=true;
//@$domdoc->loadHTMLFile($baseUrl);
@$domdoc->loadHTML($baseUrl);
$links = $domdoc->getElementsByTagName('a');
$i = 0;
$count = 0;
$data = array();
foreach($links as $link)
{
//echo $domdoc->saveXML($link);
if($link->getAttribute('href'))
{
if(!$link->hasAttribute('id') || $link->getAttribute('id')!='streams')
{
$url = str_replace("rtmp://", "", $link->getAttribute('href'));
$url = str_replace(" ", "%20", $link->getAttribute('href'));
//echo $url;
//echo "<br>";
$sdoc = new DOMDocument();
$sdoc->strictErrorChecking = false;
$sdoc->recover=true;
@$sdoc->loadHTMLFile($url);
$time1_span = $sdoc->getElementById('time1');
//$spans = $sdoc->getElementsByTagName('time1');
$query = parse_url($url)['query'];
$channel_split = explode("&", $query)[0];
$channel = urldecode(explode("=",$channel_split)[1]);
$id_split = explode("&", $query)[1];
$my_id = urldecode(explode("=",$id_split)[1]);
$xpath = new DOMXpath($sdoc);
$time1 = $xpath->query("*/span[@id='time1']");
//$time2 = $xpath->query("*/span[@id='time2']");
//$time3 = $xpath->query("*/span[@id='time3']");
//$time4 = $xpath->query("*/span[@id='time4']");
$array = array(
$time1,
);
// Save the output format
$DATE_FORMAT_STRING = "YmdHis";
// GET the current STAGE
$current_state = getState($array[0]);
$offset = 0;
$flag = 0;
foreach($array as $time)
{
// Get the item state.
$this_state = getState($time);
// check if we past a day?
if($current_state == "PM" && $this_state == "AM")
{
$offset++;
}
$this_unix = strtotime($time) + (60 * 60 * 24 * $offset);
$values[] = date($DATE_FORMAT_STRING, $this_unix);
//echo date($DATE_FORMAT_STRING, $this_unix);
echo $values[0];
echo "<br></br>";
$current_state = $this_state;
$count++;
}
}
}
}
?>
您知道为什么我会收到警告错误,您知道如何修复它吗?
答案 0 :(得分:0)
$this_state = getState($time);
此时,$time
为$xpath->query("*/span[@id='time1']");
XPath查询返回节点列表。一个东西。即不是字符串。
你有意这么说吗?
$this_state = getState($time->item(0)->nodeValue);