1

我有一个很好用的脚本

<form name="contactform" method="POST" action="mssql.php">
<textarea name="user" cols="20" rows="6"></textarea>
<textarea name="pass" cols="20" rows="6"></textarea>
<input type="submit" value="Submit" />
</form>

<?php

$user = $_POST['user'];
$lines = explode("\n", $user);
$pass = $_POST['pass'];
$lines1 = explode("\n", $pass);

echo "Paste into command line to add user and passwords<br><br>";
echo "=======================================<br><br>";

foreach (array_combine($lines, $lines1) as $v => $t) {
        echo "CREATE LOGIN " . $v . " WITH PASSWORD = '" . $t . "';<br>GO<br>";
}
echo "=======================================<br><br>";

?>

唯一的问题是输出:

Paste into command line to add user and passwords

=======================================
CREATE LOGIN user1 WITH PASSWORD = 'pass1 ';
GO
CREATE LOGIN user2 WITH PASSWORD = 'pass2';
GO
=======================================

注意 pass1 --> 'pass1' 后面的空格;

我该如何摆脱它?

谢谢你

4

2 回答 2

1

利用trim()

echo "CREATE LOGIN " . trim($v) . 
   " WITH PASSWORD = '" . trim($t) . "';<br>GO<br>";
于 2013-09-20T05:00:07.813 回答
0

试试看trim_

foreach (array_combine($lines, $lines1) as $v => $t) {
    $t = trim($t);
    echo "CREATE LOGIN " . $v . " WITH PASSWORD = '" . $t . "';<br>GO<br>";
}

trim函数返回一个字符串,从字符串的开头和结尾去除空格。请参阅此链接

于 2013-09-20T04:59:39.833 回答