简单的PHP加密程序
我不太清楚为什么这个简单的PHP脚本不起作用 我的浏览器无法加载该页面。我认为这是逻辑上的缺陷,而不是语法上的缺陷,但也许这里有人能指出我的错误简单的PHP加密程序,php,Php,我不太清楚为什么这个简单的PHP脚本不起作用 我的浏览器无法加载该页面。我认为这是逻辑上的缺陷,而不是语法上的缺陷,但也许这里有人能指出我的错误 <html> <head> <title>My Encryption Program</title> </head> <body> <?PHP $ConvertedLetter =""; $SecretMessa
<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>
我的加密程序
这应该适合您:
<?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;
?>
有关更多信息,请参阅:
<?php
ini_set("display_errors", 1);
error_reporting(E_ALL);
?>
在你犯错误之前:
,不是(但在定义的相同情况下编写它们仍然是一种良好的做法)
还有一些参考资料可以帮助你将来自己解决这些问题,或者至少更快地得到答案(悬停在上面!vvv) 谷歌是你最好的朋友!(他永远不会对你撒谎,相信我:D)
搜索某些东西总是一个好的开始
这将帮助您快速获得答案
您的循环将运行无限次…非常感谢您的耐心。您的回答帮助我确定了哪里出了问题。我知道这看起来像是我在没有事先研究的情况下发布的,但事实并非如此。当你刚开始编程时,最简单的事情可能会让你绊倒,而自学基础知识可能需要很长时间。@RickTicky不客气!祝你度过愉快的一天:D(顺便说一句:我在底部更新了我的答案,添加了一些参考资料)@RickTicky顺便说一句:你可以接受这个答案,它对你帮助最大,解决了你的问题!)非常抱歉。我对你的答案投了赞成票,但没有中肯。你现在已经这样做了!
<?php
ini_set("display_errors", 1);
error_reporting(E_ALL);
?>