重构+帮助 [英] refactor + help

查看:59
本文介绍了重构+帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于这个问题,可能有一个非常简单的解决方案,但

我似乎无法弄明白。希望你们中的一位大师可以提供帮助。


今天我正在搞乱PHP,我写了一个小应用程序,询问

为你的名字和邮政编码。如果您的邮政编码少于5个字符,

它会要求您输入一个包含适当字符数的邮政编码。


这里是代码:


< code>

<?php


print<<< _HTML_


< form method =''POST''action =''$ _ SERVER [PHP_SELF]''>

名称:< input type =' 'text''name =''name''>< br />< br />

邮政编码:< input type =''text''name =''zipcode ''>< br />< br />

< input type =''submit''value ='''Step 2 ...''>

< / form>

_HTML_;


$ zipcode = trim($ _ POST [''zipcode'']);


$ zip_length = strlen($ zipcode);


print $ _POST [''zipcode''];


if($ zip_length!= 5){


打印''无效字符数'';


} else {


prin t''';


}


?>


< / code> ;


我无法弄清楚如何在信息通过表单传递之后如何获得''无效字符数''

字符串帖子。相反它

在页面底部显示该字符串而没有任何

干预。我知道答案就在我的面前。

也许有人可以提供帮助?

谢谢!

There is probably an incredibly simple solution for this problem, but
I can''t seem to figure it out. Hopefully one of you gurus can help.

I''m was messing around with PHP today and I wrote a tiny app that asks
for your name and zipcode. If your zipcode is less than 5 characters,
it asks you too enter a zip code with the proper amount of characters.

Here''s the code:

<code>
<?php

print <<<_HTML_

<form method=''POST'' action=''$_SERVER[PHP_SELF]''>
Name: <input type=''text'' name=''name''><br /><br />
Zipcode: <input type=''text'' name=''zipcode''><br /><br />
<input type=''submit'' value=''Step 2...''>
</form>
_HTML_;

$zipcode = trim($_POST[''zipcode'']);

$zip_length = strlen($zipcode);

print $_POST[''zipcode''];

if ($zip_length != 5){

print ''invalid amount of characters'';

} else {

print '' '';

}

?>

</code>

I cannot figure out how to have the the ''invalid amount of characters''
string post only after the info is passed through the form. Instead it
displays that string on the bottom of the page without any
intervention. I know the answer is sitting right in front of my face.
Maybe someone can help?
Thanks!

推荐答案

_SERVER [PHP_SELF]''>

名称:< input type =''text''name =''name''>< br /> < br />

邮政编码:< input type =''text''name =''zipcode''>< br />< br />

< input type =''submit''value =''Step 2 ...''>

< / form>

_HTML_ ;

_SERVER[PHP_SELF]''>
Name: <input type=''text'' name=''name''><br /><br />
Zipcode: <input type=''text'' name=''zipcode''><br /><br />
<input type=''submit'' value=''Step 2...''>
</form>
_HTML_;


zipcode = trim(
zipcode = trim(


_POST [''zipcode'']);

_POST[''zipcode'']);


这篇关于重构+帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆