【发布时间】:2016-01-30 21:58:13
【问题描述】:
Zack here.. 我最近在使用 URL Shortener 时遇到了问题。您能检查下面的代码是否有错误吗?非常感谢!
<?php
$db = new mysqli("localhost","pretzel_main","00WXE5fMWtaVd6Dd","pretzel");
function code($string_length = 3) {
$permissible_characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$char_length = strlen($permissible_characters);
$random = '';
for ($i = 0; $i < $string_length; $i++) {
$random .= $permissible_characters[rand(0, $char_length - 1)];
}
return $random;
}
if (substr($_POST['long'], 0, 7) == http://) {
$url = $_POST['long'];
} elseif (substr($_POST['long'], 0, 8) == https://) {
$url = $_POST['long'];
} else {
$url = "http://".$_POST['long'];
}
$result = $db->prepare("INSERT INTO links VALUES('',?,?)");
$result->bind_param("ss",$url, $title);
$result->execute();
$title = $code();
?>
祝你好运,提前致谢! - 扎克
【问题讨论】:
-
){]$=> 这无效...打开你的错误报告 -
@ZDavies 不,它已经随你编辑消失了,所以可能是一个错字。但是这个
$code();还是不好 -
什么你遇到了什么麻烦?具体错误。
-
@Blag 为什么不是 Blag?
-
@ZDavies 因为
$code();的意思是$code = 'functionName'; {$code}(); /*same as*/ functionName();又名你不需要$在你的函数调用之前我认为:$title = code();