php最佳实践 [英] php best practise

查看:55
本文介绍了php最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我是一个php新手,虽然我已经是程序员多年了,这可能是

很危险,因为我所知道的所有语言都使用=作为相同的比较所以它

花了我很长时间来调试if($ STRING =''fred''){没有意识到我是

将fred分配给$ STRING和评价永远是真的!需要花费很长时间才能发现($ STRING = =''fred''){。


我最终成功创建了一个经过验证的表格显示

错误列表,但我有一些关于''最佳实践''编程的问题

因为我的解决方案看起来有点笨拙:


组合框选择:如何设置默认值或记住选择用户

的内容,以便重新显示表单及其选择。我这样做了:Item1

=''< - 选择国家/地区 - >如果选中,我然后使用echo将文本更改为

实际选择,如果表单重新显示,问题:如何动态设置默认值
或者动态移动SELECTED标签?


<选择选项><?echo $ COUNTRY?>< / option>

< option>阿富汗< /选项>

<选项>阿尔巴尼亚< /选项>

<选项>阿尔及利亚< /选项>

收音机按钮:我给每个人分配了一个<? echoDEFAULT1?>,<? echo DEFAULT2

?>等,并将每个设置为除了我真正想要的默认值,这是设置

到已检查,我肯定不是这样做的正确方法吗?

< input type ="无线电"值= QUOT; MSWORD" <?echo $ CKWORD?> name =" RB1"

tabindex =" 14"> Microsoft Word< br>

< input type =" radio"值= QUOT; TXT" <?echo $ CKTXT?> name =" RB1"

tabindex =" 15"> Text File< br>

< input type =" radio"值= QUOT; PDF" <?echo $ CKPDF?> name =" RB1"

tabindex =" 16">可移植文档格式(PDF)< / td>


TIA


Barry

Hi

I am a php newbie although I have been a programmer for years, this can be
dangerous because all the languages I know use = as equal comparison so it
took me a long time to debug if ($STRING = ''fred'') { not realising I was
assigning fred to $STRING and the evaluation is always true! It took ages to
discover if ($STRING = = ''fred'') {.

I eventually managed to create a validated form which re-displays with an
error list, but I have a few questions about ''best practise'' programming
because my solutions seem a little clumsy:

Combobox selection: How do you set a default or remember what the user
selected so the form is re-displayed with their selection. I did this: Item1
= ''< -- Select a Country --> as "selected", I then changed the text to the
actual selection using echo if the form is re-displayed, Question: How do
you dynamically set a default or dynamically move the SELECTED tag?

<option selected><?echo $COUNTRY?></option>
<option>Afghanistan</option>
<option>Albania</option>
<option>Algeria</option>
Radio Buttons: I assigned each with a <? echoDEFAULT1 ?>, <? echo DEFAULT2
?> etc and set each to "" except for the default I really want, this is set
to "checked", surely I am not doing this the right way?
<input type="radio" value="MSWORD" <?echo $CKWORD?> name="RB1"
tabindex="14">Microsoft Word<br>
<input type="radio" value="TXT" <?echo $CKTXT?> name="RB1"
tabindex="15">Text File<br>
<input type="radio" value="PDF" <?echo $CKPDF?> name="RB1"
tabindex="16">Portable Document Format (PDF)</td>

TIA

Barry

推荐答案

STRING =''fred''){没有意识到我是
将fred分配给
STRING = ''fred'') { not realising I was
assigning fred to


STRING,评估始终是真的!需要花费很长时间才能发现(
STRING and the evaluation is always true! It took ages to
discover if (


STRING = =''fred''){。


I最终成功创建了一个经过验证的表单,用

错误列表重新显示,但我有一些关于''最佳实践''编程的问题

,因为我的解决方案似乎有点笨拙:


组合框选择:如何设置默认值或记住用户选择的
,以便重新显示表单及其选择。我这样做了:Item1

=''< - 选择国家/地区 - >如果选中,我然后使用echo将文本更改为

实际选择,如果表单重新显示,问题:如何动态设置默认值
或者动态移动SELECTED标签?


<选择选项><?echo
STRING = = ''fred'') {.

I eventually managed to create a validated form which re-displays with an
error list, but I have a few questions about ''best practise'' programming
because my solutions seem a little clumsy:

Combobox selection: How do you set a default or remember what the user
selected so the form is re-displayed with their selection. I did this: Item1
= ''< -- Select a Country --> as "selected", I then changed the text to the
actual selection using echo if the form is re-displayed, Question: How do
you dynamically set a default or dynamically move the SELECTED tag?

<option selected><?echo


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

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