我试图通过它的长度验证一个数字.此号码必须有4位数字才能通过验证.问题是这个数字的左边是0,比如0035.
现在我在这:
echo (strlen ((string) 0025 ));
Run Code Online (Sandbox Code Playgroud)
总共给出了2,但是我想要把它计算为左边的0,所以它给了我总共4个.显然整数到字符串的转换不起作用,我怎么能这样做?
我正在尝试构建一个小的备份脚本,但我不断收到以下错误:
tar: Removing leading `/' from member names
tar: /projects: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors
Run Code Online (Sandbox Code Playgroud)
文件夹/项目存在,但仍然没有创建tar球.这是我的代码:
#!/bin/bash
backup_files="/projects"
#destination of backup
dest="/"
#Create archive filename
day=$(date +%Y-%m-%d)
hostname=$(hostname -s)
archive_file="$hostname-$day.tar.gz"
#Backup the files using tar
tar -czf $archive_file $backup_files
#Print end status message
echo
echo "Backup finished"
Run Code Online (Sandbox Code Playgroud)
ls -ld/projects显示以下内容:
ls: cannot access /projects: No such file or directory
Run Code Online (Sandbox Code Playgroud)
什么是错的?
我想在lisp中创建一个函数,它接收一个数字和一对对的列表,并遍历对列表,并删除对的第一个元素和第二个元素之间的除法结果. pair与作为参数传递的数字不同.最后它返回一个列表,其中只包含除法结果相同的列表.
到目前为止,我有以下代码:
(defun retira-terco(num l1)
(cond ((null l1) ())
((not (equal num (/ (car(first l1)) (cdr(first l1)))))
(retira-terco num (rest l1)))
(t (cons (first l1) (retira-terco num (rest l1))))))
Run Code Online (Sandbox Code Playgroud)
当我尝试使用一个真实示例运行此示例时,我收到以下错误:
Error: `(1)' is not of the expected type `NUMBER'
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我目前正在尝试使用 Guzzle 通过 Oauth 开发与 Reddit api 的连接。我到达了在 Reddit 中进行身份验证的阶段,然后获得了授权令牌,但我无法从 Guzzle 响应中获取访问令牌,因此我可以将其设置为 cookie 并在后续请求中使用。我当前的代码如下所示:
public function __construct(){
if(isset($_COOKIE['reddit_token'])){
$token_info = explode(":", $_COOKIE['reddit_token']);
$this->token_type = $token_info[0];
$this->access_token = $token_info[1];
} else {
if (isset($_GET['code'])){
//capture code from auth
$code = $_GET["code"];
//construct POST object for access token fetch request
$postvals = sprintf("code=%s&redirect_uri=%s&grant_type=authorization_code",
$code,
redditConfig::$ENDPOINT_OAUTH_REDIRECT);
//get JSON access token object (with refresh_token parameter)
$token = self::runCurl(redditConfig::$ENDPOINT_OAUTH_TOKEN, $postvals, null, true);
//store token and type
if (isset($token->access_token)){
$this->access_token = $token->access_token;
$this->token_type = $token->token_type;
//set …Run Code Online (Sandbox Code Playgroud)