【发布时间】:2018-09-12 13:33:36
【问题描述】:
如何将以下对象转换为字符串:
$ssh->exec('tail -1 /var/log/playlog.csv');
所以我可以将字符串解析为 strripos() 中的第一个参数:
if($idx = strripos($ssh,','))//Get the last index of ',' substring
{
$ErrorCode = substr($ssh,$idx + 1,(strlen($ssh) - $idx) - 1); //using the found index, get the error code using substring
echo " " .$Playlist.ReturnError($ErrorCode); //The ReturnError function just replaces the error code with a custom error
}
目前,当我运行我的脚本时,我收到以下错误消息:
strpos() expects parameter 1 to be string
我见过类似的问题,包括这个 Object of class stdClass could not be converted to string ,但我似乎仍然无法提出解决方案。
【问题讨论】:
-
$ssh的类型是什么?你应该在$ssh->exec()返回的值上strripos(),而不是$ssh。 -
这就是我想要实现的目标,我正在考虑将
$ssh变量(即类型对象)的输出转换为字符串,然后将该字符串解析为strripos() -
@axiac 可能是,猜我们需要看看 OP 是否回复。
-
@axiac 我同意
strripos($ssh不起作用,因为$ssh不是字符串,所以它不起作用。没有$ssh定义虽然很难说,除了说分配回报。如果返回是一个对象,甚至是 NULL,则分配返回将不起作用。我想我会删除该评论,直到他们的exec所做的事情清楚为止。
标签: php string object ssh ssh2-exec