创建/删除空格分隔的文件夹名称

问题描述 投票:0回答:2

当我尝试创建一个名称以空格分隔的文件夹时,它只占用第一个单词而忽略第二个单词。我该如何解决这个问题?我正在用php写一个dovecot服务器。 LIST给出的空间分隔符是“/”。

代码:

private const NEWLINE  = "\r\n";
private socket = fsockopen("ssl://testmail.com", 465, $errno, $errstr, 
20);
$foldername = "Hello World"
function createFolder($socket, $foldername) {
fputs($socket, "A3 Create " . $foldername . self::NEWLINE)

return read($socket);}

function read($socket)
{

stream_set_timeout($socket, 30);
$lines = [];

while(\FALSE !== ($line = fgets($socket))) {
    $lines[] = $line;

    if (\FALSE !== strpos($line, 'BAD')) {
        break;
    }

    if (\FALSE !== strpos($line, 'NO')) {
        break;
    }

    if (\FALSE !== strpos($line, 'OK')) {
        break;
    }

    if (\FALSE === strpos($line, 'OK')) {
        continue;
    }
}

return $lines;}

我试过转义字符串并以不同的方式编写它,但似乎没有任何工作。它确实创建了一个文件夹,但如上所述只有第一个单词。服务器回复:

array(1) {[0]=>string(25) "A3 OK Create completed."}

编辑:以下是我尝试过的一些事情,一次是通过修改fput然后在玩字符串时:

fputs($socket, "A3 Create " . \$foldername . self::NEWLINE)  Result: HTTP ERROR 500
fputs($socket, "A3 Create " . '$foldername' . self::NEWLINE) Result: $foldername
fputs($socket, "A3 Create " . "$foldername" . self::NEWLINE) Result: Hello
fputs($socket, "A3 Create " . '\$foldername . self::NEWLINE) Result: \$foldername
fputs($socket, "A3 Create " . 'Hello' . 'World' . self::NEWLINE)   Result: HelloWorld
fputs($socket, "A3 Create " . 'Hello ' . 'World' . self::NEWLINE)   Result: Hello
fputs($socket, "A3 Create " . "Hello " . "World" . self::NEWLINE)   Result: Hello


$foldername = "'Hello World'";         Result: 'Hello
$foldername = '"Hello  World"';        Result: Hello
$foldername = 'Hello World';           Result: Hello
$foldername = "'Hello \ World'";       Result: 'Hello
$foldername = "<<<EOD Hello World EOD";  Result: <<<EOD
$foldername = '<<<EOD Hello World EOD';  Result: <<<EOD
$foldername = <<<EOD Hello World EOD;  Result: Hello
$foldername = "%Hello  World%";        Result: %Hello
$foldername = '%Hello  World%';        Result: %Hello
$foldername = '\Hello  World';         Result: \Hello
$foldername = "\Hello  World";         Result: \Hello
php imap dovecot
2个回答
1
投票

这件作品:$foldername = '"Hello\\ World"';


0
投票

将其括在引号中,以便发送:

A4 CREATE "Folder Name"

PHP不是我的语言,但据推测,像$foldername = '"Folder Name"'这样的东西会让你得到你想要的东西。

© www.soinside.com 2019 - 2024. All rights reserved.