太空我无法摆脱

时间:2013-09-20 04:58:33

标签: php sql-server

我有一个效果很好的脚本

<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后面的空格 - &gt; 'pass1';

我该如何摆脱它?

谢谢

2 个答案:

答案 0 :(得分:1)

使用trim()

echo "CREATE LOGIN " . trim($v) . 
   " WITH PASSWORD = '" . trim($t) . "';<br>GO<br>";

答案 1 :(得分:0)

尝试trim喜欢

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

trim函数返回一个字符串,其字符串从string的开头和结尾处去掉。请参阅LINK