从php执行时,额外的文本来自shell_exec命令

[英]Extra text comes from shell_exec command when executed from php


I am using s3cmd to get files from AWS to my ubuntu server.

我使用s3cmd从AWS获取文件到我的ubuntu服务器。

s3cmd get s3://bucket/filename newfilename

It works fine when run from terminal of ubuntu.

从ubuntu的终端运行时它工作正常。

But when I run from php like below

但是当我从下面的php运行时

$query1 = 's3cmd get s3://bucket/filename newfilename';
$q1 = serialize(shell_exec($query1));
$data2 = array( 'data' => $q1);
header('Content-type: application/json');
echo json_encode( $data2 );

It works but response from json_encode it concatenated with extra text.

它的工作原理是json_encode的响应,它与额外的文本连接起来。

{"data":"s:122:\"File s3:............

What is s:122 and how to remove this. I am not looking for sub_string though.

什么是s:122以及如何删除它。我不是在寻找sub_string。

1 个解决方案

#1


1  

When you serialize some value - in a result string there's type of value and value itself. s:122, you asked about, says that values is a string with length 122. So if you don't want this string appear - don't serialize value.

序列化某个值时 - 在结果字符串中有值和值本身的类型。 s:122,你问过,说值是一个长度为122的字符串。所以如果你不想出现这个字符串 - 不要序列化值。

智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2015/09/19/71d4a4ab764e68e3e711f25efde00805.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告