我不确定为什么这个简单的PHP脚本无效,
我的浏览器无法加载页面。我认为它是逻辑上的缺陷而不是语法,但也许这里的某个人会很友好地指出我出错的原因/原因。
<html>
<head>
<title>My Encryption Program</title>
</head>
<body>
<?PHP
$ConvertedLetter ="";
$SecretMessage= "Kiss My Shiny Metal...";
$MessageLength = strlen($SecretMessage);
$Counter = 0;
For($Counter;$MessageLength;$Counter++){
$LetterToEncrypt = substr($SecretMessage,$Counter,1);
$AsciiNumber = ord($LetterToEncrypt) + 3;
$ConvertedLetter = $ConvertedLetter + Chr($AsciiNumber);
}
echo $ConvertedLetter;
?>
</body>
</html>
答案 0 :(得分:7)
这应该适合你:
<?php
//^^^ good practice in lowercase
$ConvertedLetter ="";
$SecretMessage= "Kiss My Shiny Metal...";
$MessageLength = strlen($SecretMessage);
for($Counter = 0; $Counter < $MessageLength; $Counter++) {
//^ ^^^^^^^^^^^^ ^^^^^^^^^^ You need a condition for a for loop
//| | Initialize the variable
//| good practice control structure in lowercase
$LetterToEncrypt = $SecretMessage[$Counter];
//^^^^^^^^^^^^^^^^^^^^^^^^ You can access a string like an array
$AsciiNumber = ord($LetterToEncrypt) + 3;
$ConvertedLetter .= chr($AsciiNumber);
//^^ ^^^ wrote the function name in the same case as it is defined
//| Append the string
}
echo $ConvertedLetter;
?>
输出:
Nlvv#P|#Vklq|#Phwdo111
有关详细信息,请参阅:
旁注:
仅在暂存时将error reporting添加到文件顶部,而不是在生产中:
<?php
ini_set("display_errors", 1);
error_reporting(E_ALL);
?>
在你犯错误之前:
Variables are case-sensitive,functions没有(但在定义相同的情况下编写它们仍然是不错的做法)!
一些参考文献可以帮助您将来自己解决此类问题或至少更快地得到答案(将鼠标悬停在其上!vvv)!
google Google是您最好的朋友! (他永远不会骗你,相信我:D)
php manual始终是寻找新事物的良好开端 How to ask这将帮助您快速得到答案!