国外的PHP程序员面试题目一解

一朋友说是国外的PHP程序员面试题目,解之:

题目三:
Create a class, Test3, with the following behavior:
The class must take a string of the format 
name1=value1:name2=value2:name3=value3 consisting of name and value 
pairs, separated by the : symbol. I must be able to enter as many 
pairs as I like when I call the class, the only limit is that each 
pair is formated as name=value and multiple pairs are separated by 
the : symbol.
When an object of the class is created it must end up with a variable 
for each name=value pair. The name of the variable must be the same 
as the name part of the substring and the value of the variable must 
be the same as the value part of the substring. For example:

creating an object with new Test3(“firstname=david:lastname=smith”) 
must create variables within the class:
$firstname = “david”;
$lastname = “smith”;

and new Test3(“food1=pasta:food2=chocolate”) must create variables 
within the class:
$food1 = “pasta”;
$food2 = “chocolate”;

I should be able to use any variable names and values provided they 
do not include the symbols : or =

You should then write a function print_all that will print the all 
the names of the defined variables in the class along with their 
values in the following format:
Variable 1 – Name = (whatever the actual name is), Value = (whatever 
the actual value is)
Variable 2 – Name = (whatever the actual name is), Value = (whatever 
the actual value is)
Variable 3 – Name = (whatever the actual name is), Value = (whatever 
the actual value is)
and so on until all the variables are listed.

The last line of output of the print_all function should be the words 
“The original input was “ followed by a string that is an exact 
representation of the string parameter supplied when creating the 
class object.

For example, if you did new Test3(“firstname=david:lastname=smith”) 
then the print_all function should output:

Variable 1 – Name = firstname, Value = david
Variable 2 – Name = lastname, Value = smith
The original imput was (“firstname=david:lastname=smith”)

This must work for any input string that has the correct format and 
you may not store the complete input string or directly output it to 
produce the last line of the print_all function output as that would 
be too easy.

PHP代码
  1. class Test3 {  
  2.     private $keys = array();  
  3.     function __construct($args) {  
  4.         $this->Test3($args);  
  5.     }  
  6.     function Test3($args) {  
  7.         $arr = explode(":"$args);  
  8.         foreach($arr as $v) {  
  9.             $varr = explode("="$v);  
  10.             $key = $varr[0];  
  11.             $value = $varr[1];  
  12.             $this->$key = $value;  
  13.             array_push($this->keys, $key);  
  14.         }  
  15.     }  
  16.     function print_all() {  
  17.         $ret = array();  
  18.         foreach($this->keys as $key) {  
  19.             array_push($ret$key."=".$this->$key);  
  20.         }  
  21.         return implode(":"$ret);  
  22.     }  
  23. }  
  24.   
  25. $t = new Test3("name=seaprince:name2=renothing");  
  26. print_r($t);  
  27. print $t->print_all();  
  28. ?>  

 

JSA在线压缩工具

转jindw: http://www.javaeye.com/topic/115300

JSA在线压缩工具,是java编写的,需要安装java运行环境。
这多少给一些非jav程序员带来点不便。

现在我们发布servlet在线压缩版本。无需安装,在线压缩,给非Java用户一个更加便捷的使用方式。


项目主页:http://www.xidea.org/project/jsa/
现在的在线压缩服务器由Seaprince提供。
欢迎更多有空闲服务器资源的朋友安装JSA在线服务,我将在jsa项目主页提供链接,方便大家使用。


仍外,为了避免服务器资源被恶意滥用,我们默认启用了图片验证,服务频率限制等保护设置。
给用户带来些不便,敬请谅解。

 

在本站的镜像地址为:http://jsa.eaxi.com

 

Read More

如何开始创业(转)

一次成功的创业建立在以下三个条件上:优秀的合伙人,确实有需求的产品,以及尽可能少的启动资金。绝大部分创业失败是因为它们缺少了以上这些条件中的某一项,而那些完全具备这三点的创业往往会取得成功。

让人欣慰的是,当你认真考虑它们的时候,这三点条件都是可行的,虽然可能有一点困难。鉴于成功的创业应该会让创始人富有,我们可以得出结论:富有的生活是可以实现的,只是有一点困难。

如果说在创业方面只有一点我想要澄清的话,那就是:创业时,并没有需要特别出众的才华才能踏出的,神奇的一步。

Read More

中国惠普前总裁孙振耀谈工作与生活

我有个有趣的观察,外企公司多的是25-35岁的白领,40岁以上的员工很少,二三十岁的外企员工是意气风发的,但外企公司40岁附近的经理人是很尴尬的。我见过的40岁附近的外企经理人大多在一直跳槽,最后大多跳到民企,比方说,唐骏。外企员工的成功很大程度上是公司的成功,并非个人的成功,西门子的确比国美大,但并不代表西门子中国经理比国美的老板强,甚至可以说差得很远。而进外企的人往往并不能很早理解这一点,把自己的成功90%归功于自己的能力,实际上,外企公司随便换个中国区总经理并不会给业绩带来什么了不起的影响。好了问题来了,当这些经理人40多岁了,他们的薪资要求变得很高,而他们的才能其实又不是那么出众,作为外企公司的老板,你会怎么选择?有的是只要不高薪水的,要出位的精明强干精力冲沛的年轻人,有的是,为什么还要用你?

Read More

王通和admin5的SEO讲课内容

大家要学习SEO,首先就要把SEO看的简单一点,其实SEO真的没有大家想象的那么复杂,不过你看了很多SEO资料后,你学习的不好
。主要是因为几个原因:
1、不认真,太多细节没有注意到
2、实践少,没有多多实践和总结
因为今天群的朋友基础不一样,所以我从最基础开始讲
SEO是Search Engine Optimization的缩写,即“搜索引擎优化”。而从事这方面工作的就是Search Engine Optimizer,即“搜索
引擎优化师”。
SEO是专门研究各大搜索引擎排名的技术,是数百种低成本网站推广策略中最常用和长期有效的营销手段之一。
既然是研究各大搜索引擎排名的技术,我们要考虑的第一个问题就是:
全球的搜索引擎都喜欢把什么样的网站,放到搜索结果的自然排名前面
答案非常简单: 肯定是优秀的网站!
那么,什么样的网站才是优秀的网站呢?
1、内容是用户需要的内容
2、网站的各方面设计细节要符合搜索引擎的标准? 

Read More

如何关闭QQ空间?

从最开始因为好奇而开通 Qzone 到现在,我就没觉得那空间有什么优点,也许唯一的优点就是与 QQ 的紧密结合。还记得以前有要紧的事需要更新空间还得起个大早,赶着网速快才能打得开。现在的速度貌似改善了许多,但幼稚的风格、对高分辨率显示的不支持、多种代码的封闭,以及最可恶的就是腾讯一切向钱看的精神。

Read More

PHP日历算法,公历农历换算

PHP代码
  1. ###########################################  
  2. #作者: 沈潋(S&S Lab) #  
  3. #E-mail:shenlian@hotmail.com #  
  4. #web: 点击查看链接 #  
  5. # #  
  6. #版权声明: #  
  7. #作者开放版权 #  
  8. #允许无条件地使用本文件的全部或部分 #  
  9. #可作任何修改或增补 #  
  10. #如果您使用了本文件,请给作者写一封E-mail #  
  11. #如有问题欢迎同作者联系 #  
  12. #谢谢您的关注! #  
  13. ###########################################  
  14. /* 
  15. *修改:小许 
  16. *mail: san@xfocus.org 
  17. *web : 点击查看链接 
  18. * 
  19. *说实在的,我对古历可以说一窍不通,下面这个数组还是不理解 可是作者的信箱好像不通 
  20. *基本上是依样画葫芦,所以出现错误,见笑见笑,呵呵 
  21. */  
  22. #农历每月的天数  
  23.   
  24. $everymonth=array(  
  25.   
  26. 0=>array(8,0,0,0,0,0,0,0,0,0,0,0,29,30,7,1),  
  27. 1=>array(0,29,30,29,29,30,29,30,29,30,30,30,29,0,8,2),  
  28. 2=>array(0,30,29,30,29,29,30,29,30,29,30,30,30,0,9,3),  
  29. 3=>array(5,29,30,29,30,29,29,30,29,29,30,30,29,30,10,4),  
  30. 4=>array(0,30,30,29,30,29,29,30,29,29,30,30,29,0,1,5),  
  31. 5=>array(0,30,30,29,30,30,29,29,30,29,30,29,30,0,2,6),  
  32. 6=>array(4,29,30,30,29,30,29,30,29,30,29,30,29,30,3,7),  
  33. 7=>array(0,29,30,29,30,29,30,30,29,30,29,30,29,0,4,8),  
  34. 8=>array(0,30,29,29,30,30,29,30,29,30,30,29,30,0,5,9),  
  35. 9=>array(2,29,30,29,29,30,29,30,29,30,30,30,29,30,6,10),  
  36. 10=>array(0,29,30,29,29,30,29,30,29,30,30,30,29,0,7,11),  
  37. 11=>array(6,30,29,30,29,29,30,29,29,30,30,29,30,30,8,12),  
  38. 12=>array(0,30,29,30,29,29,30,29,29,30,30,29,30,0,9,1),  
  39. 13=>array(0,30,30,29,30,29,29,30,29,29,30,29,30,0,10,2),  
  40. 14=>array(5,30,30,29,30,29,30,29,30,29,30,29,29,30,1,3),  
  41. 15=>array(0,30,29,30,30,29,30,29,30,29,30,29,30,0,2,4),  
  42. 16=>array(0,29,30,29,30,29,30,30,29,30,29,30,29,0,3,5),  
  43. 17=>array(2,30,29,29,30,29,30,30,29,30,30,29,30,29,4,6),  
  44. 18=>array(0,30,29,29,30,29,30,29,30,30,29,30,30,0,5,7),  
  45. 19=>array(7,29,30,29,29,30,29,29,30,30,29,30,30,30,6,8),  
  46. 20=>array(0,29,30,29,29,30,29,29,30,30,29,30,30,0,7,9),  
  47. 21=>array(0,30,29,30,29,29,30,29,29,30,29,30,30,0,8,10),  
  48. 22=>array(5,30,29,30,30,29,29,30,29,29,30,29,30,30,9,11),  
  49. 23=>array(0,29,30,30,29,30,29,30,29,29,30,29,30,0,10,12),  
  50. 24=>array(0,29,30,30,29,30,30,29,30,29,30,29,29,0,1,1),  
  51. 25=>array(4,30,29,30,29,30,30,29,30,30,29,30,29,30,2,2),  
  52. 26=>array(0,29,29,30,29,30,29,30,30,29,30,30,29,0,3,3),  
  53. 27=>array(0,30,29,29,30,29,30,29,30,29,30,30,30,0,4,4),  
  54. 28=>array(2,29,30,29,29,30,29,29,30,29,30,30,30,30,5,5),  
  55. 29=>array(0,29,30,29,29,30,29,29,30,29,30,30,30,0,6,6),  
  56. 30=>array(6,29,30,30,29,29,30,29,29,30,29,30,30,29,7,7),  
  57. 31=>array(0,30,30,29,30,29,30,29,29,30,29,30,29,0,8,8),  
  58. 32=>array(0,30,30,30,29,30,29,30,29,29,30,29,30,0,9,9),  
  59. 33=>array(5,29,30,30,29,30,30,29,30,29,30,29,29,30,10,10),  
  60. 34=>array(0,29,30,29,30,30,29,30,29,30,30,29,30,0,1,11),  
  61. 35=>array(0,29,29,30,29,30,29,30,30,29,30,30,29,0,2,12),  
  62. 36=>array(3,30,29,29,30,29,29,30,30,29,30,30,30,29,3,1),  
  63. 37=>array(0,30,29,29,30,29,29,30,29,30,30,30,29,0,4,2),  
  64. 38=>array(7,30,30,29,29,30,29,29,30,29,30,30,29,30,5,3),  
  65. 39=>array(0,30,30,29,29,30,29,29,30,29,30,29,30,0,6,4),  
  66. 40=>array(0,30,30,29,30,29,30,29,29,30,29,30,29,0,7,5),  
  67. 41=>array(6,30,30,29,30,30,29,30,29,29,30,29,30,29,8,6),  
  68. 42=>array(0,30,29,30,30,29,30,29,30,29,30,29,30,0,9,7),  
  69. 43=>array(0,29,30,29,30,29,30,30,29,30,29,30,29,0,10,8),  
  70. 44=>array(4,30,29,30,29,30,29,30,29,30,30,29,30,30,1,9),  
  71. 45=>array(0,29,29,30,29,29,30,29,30,30,30,29,30,0,2,10),  
  72. 46=>array(0,30,29,29,30,29,29,30,29,30,30,29,30,0,3,11),  
  73. 47=>array(2,30,30,29,29,30,29,29,30,29,30,29,30,30,4,12),  
  74. 48=>array(0,30,29,30,29,30,29,29,30,29,30,29,30,0,5,1),  
  75. 49=>array(7,30,29,30,30,29,30,29,29,30,29,30,29,30,6,2),  
  76. 50=>array(0,29,30,30,29,30,30,29,29,30,29,30,29,0,7,3),  
  77. 51=>array(0,30,29,30,30,29,30,29,30,29,30,29,30,0,8,4),  
  78. 52=>array(5,29,30,29,30,29,30,29,30,30,29,30,29,30,9,5),  
  79. 53=>array(0,29,30,29,29,30,30,29,30,30,29,30,29,0,10,6),  
  80. 54=>array(0,30,29,30,29,29,30,29,30,30,29,30,30,0,1,7),  
  81. 55=>array(3,29,30,29,30,29,29,30,29,30,29,30,30,30,2,8),  
  82. 56=>array(0,29,30,29,30,29,29,30,29,30,29,30,30,0,3,9),  
  83. 57=>array(8,30,29,30,29,30,29,29,30,29,30,29,30,29,4,10),  
  84. 58=>array(0,30,30,30,29,30,29,29,30,29,30,29,30,0,5,11),  
  85. 59=>array(0,29,30,30,29,30,29,30,29,30,29,30,29,0,6,12),  
  86. 60=>array(6,30,29,30,29,30,30,29,30,29,30,29,30,29,7,1),  
  87. 61=>array(0,30,29,30,29,30,29,30,30,29,30,29,30,0,8,2),  
  88. 62=>array(0,29,30,29,29,30,29,30,30,29,30,30,29,0,9,3),  
  89. 63=>array(4,30,29,30,29,29,30,29,30,29,30,30,30,29,10,4),  
  90. 64=>array(0,30,29,30,29,29,30,29,30,29,30,30,30,0,1,5),  
  91. 65=>array(0,29,30,29,30,29,29,30,29,29,30,30,29,0,2,6),  
  92. 66=>array(3,30,30,30,29,30,29,29,30,29,29,30,30,29,3,7),  
  93. 67=>array(0,30,30,29,30,30,29,29,30,29,30,29,30,0,4,8),  
  94. 68=>array(7,29,30,29,30,30,29,30,29,30,29,30,29,30,5,9),  
  95. 69=>array(0,29,30,29,30,29,30,30,29,30,29,30,29,0,6,10),  
  96. 70=>array(0,30,29,29,30,29,30,30,29,30,30,29,30,0,7,11),  
  97. 71=>array(5,29,30,29,29,30,29,30,29,30,30,30,29,30,8,12),  
  98. 72=>array(0,29,30,29,29,30,29,30,29,30,30,29,30,0,9,1),  
  99. 73=>array(0,30,29,30,29,29,30,29,29,30,30,29,30,0,10,2),  
  100. 74=>array(4,30,30,29,30,29,29,30,29,29,30,30,29,30,1,3),  
  101. 75=>array(0,30,30,29,30,29,29,30,29,29,30,29,30,0,2,4),  
  102. 76=>array(8,30,30,29,30,29,30,29,30,29,29,30,29,30,3,5),  
  103. 77=>array(0,30,29,30,30,29,30,29,30,29,30,29,29,0,4,6),  
  104. 78=>array(0,30,29,30,30,29,30,30,29,30,29,30,29,0,5,7),  
  105. 79=>array(6,30,29,29,30,29,30,30,29,30,30,29,30,29,6,8),  
  106. 80=>array(0,30,29,29,30,29,30,29,30,30,29,30,30,0,7,9),  
  107. 81=>array(0,29,30,29,29,30,29,29,30,30,29,30,30,0,8,10),  
  108. 82=>array(4,30,29,30,29,29,30,29,29,30,29,30,30,30,9,11),  
  109. 83=>array(0,30,29,30,29,29,30,29,29,30,29,30,30,0,10,12),  
  110. 84=>array(10,30,29,30,30,29,29,30,29,29,30,29,30,30,1,1),  
  111. 85=>array(0,29,30,30,29,30,29,30,29,29,30,29,30,0,2,2),  
  112. 86=>array(0,29,30,30,29,30,30,29,30,29,30,29,29,0,3,3),  
  113. 87=>array(6,30,29,30,29,30,30,29,30,30,29,30,29,29,4,4),  
  114. 88=>array(0,30,29,30,29,30,29,30,30,29,30,30,29,0,5,5),  
  115. 89=>array(0,30,29,29,30,29,29,30,30,29,30,30,30,0,6,6),  
  116. 90=>array(5,29,30,29,29,30,29,29,30,29,30,30,30,30,7,7),  
  117. 91=>array(0,29,30,29,29,30,29,29,30,29,30,30,30,0,8,8),  
  118. 92=>array(0,29,30,30,29,29,30,29,29,30,29,30,30,0,9,9),  
  119. 93=>array(3,29,30,30,29,30,29,30,29,29,30,29,30,29,10,10),  
  120. 94=>array(0,30,30,30,29,30,29,30,29,29,30,29,30,0,1,11),  
  121. 95=>array(8,29,30,30,29,30,29,30,30,29,29,30,29,30,2,12),  
  122. 96=>array(0,29,30,29,30,30,29,30,29,30,30,29,29,0,3,1),  
  123. 97=>array(0,30,29,30,29,30,29,30,30,29,30,30,29,0,4,2),  
  124. 98=>array(5,30,29,29,30,29,29,30,30,29,30,30,29,30,5,3),  
  125. 99=>array(0,30,29,29,30,29,29,30,29,30,30,30,29,0,6,4),  
  126. 100=>array(0,30,30,29,29,30,29,29,30,29,30,30,29,0,7,5),  
  127. 101=>array(4,30,30,29,30,29,30,29,29,30,29,30,29,30,8,6),  
  128. 102=>array(0,30,30,29,30,29,30,29,29,30,29,30,29,0,9,7),  
  129. 103=>array(0,30,30,29,30,30,29,30,29,29,30,29,30,0,10,8),  
  130. 104=>array(2,29,30,29,30,30,29,30,29,30,29,30,29,30,1,9),  
  131. 105=>array(0,29,30,29,30,29,30,30,29,30,29,30,29,0,2,10),  
  132. 106=>array(7,30,29,30,29,30,29,30,29,30,30,29,30,30,3,11),  
  133. 107=>array(0,29,29,30,29,29,30,29,30,30,30,29,30,0,4,12),  
  134. 108=>array(0,30,29,29,30,29,29,30,29,30,30,29,30,0,5,1),  
  135. 109=>array(5,30,30,29,29,30,29,29,30,29,30,29,30,30,6,2),  
  136. 110=>array(0,30,29,30,29,30,29,29,30,29,30,29,30,0,7,3),  
  137. 111=>array(0,30,29,30,30,29,30,29,29,30,29,30,29,0,8,4),  
  138. 112=>array(4,30,29,30,30,29,30,29,30,29,30,29,30,29,9,5),  
  139. 113=>array(0,30,29,30,29,30,30,29,30,29,30,29,30,0,10,6),  
  140. 114=>array(9,29,30,29,30,29,30,29,30,30,29,30,29,30,1,7),  
  141. 115=>array(0,29,30,29,29,30,29,30,30,30,29,30,29,0,2,8),  
  142. 116=>array(0,30,29,30,29,29,30,29,30,30,29,30,30,0,3,9),  
  143. 117=>array(6,29,30,29,30,29,29,30,29,30,29,30,30,30,4,10),  
  144. 118=>array(0,29,30,29,30,29,29,30,29,30,29,30,30,0,5,11),  
  145. 119=>array(0,30,29,30,29,30,29,29,30,29,29,30,30,0,6,12),  
  146. 120=>array(4,29,30,30,30,29,30,29,29,30,29,30,29,30,7,1)  
  147.   
  148. );  
  149. ##############################  
  150.   
  151. #农历天干  
  152.   
  153. $mten=array("null","甲","乙","丙","丁","戊","己","庚","辛","壬","癸");  
  154. #农历地支  
  155.   
  156. $mtwelve=array("null","子(鼠)","丑(牛)","寅(虎)","卯(兔)","辰(龙)",  
  157. "巳(蛇)","午(马)","未(羊)","申(猴)","酉(鸡)","戌(狗)","亥(猪)");  
  158. #农历月份  
  159.   
  160. $mmonth=array("闰","正","二","三","四","五","六",  
  161. "七","八","九","十","十一","十二","月");  
  162. #农历日  
  163.   
  164. $mday=array("null","初一","初二","初三","初四","初五","初六","初七","初八","初九","初十",  
  165. "十一","十二","十三","十四","十五","十六","十七","十八","十九","二十",  
  166. "廿一","廿二","廿三","廿四","廿五","廿六","廿七","廿八","廿九","三十");  
  167. ##############################  
  168.   
  169. #星期  
  170.   
  171. $weekday = array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");  
  172. #阳历总天数 至1900年12月21日  
  173.   
  174. $total=11;  
  175. #阴历总天数  
  176.   
  177. $mtotal=0;  
  178. ##############################  
  179.   
  180. #获得当日日期  
  181.   
  182. $today=getdate();  
  183. if($today["year"]<1901 || $today["year"]>2020) die("年份出错!");  
  184. $cur_wday=$today["wday"];  
  185. for($y=1901;$y<$today["year"];$y++) { //计算到所求日期阳历的总天数-自1900年12月21日始,先算年的和  
  186.   
  187. $total+=365;  
  188. if ($y%4==0) $total++;  
  189. }  
  190.   
  191. switch($today["mon"]) { //再加当年的几个月  
  192.   
  193. case 12:  
  194.   
  195. $total+=30;  
  196. case 11:  
  197.   
  198. $total+=31;  
  199. case 10:  
  200.   
  201. $total+=30;  
  202. case 9:  
  203.   
  204. $total+=31;  
  205. case 8:  
  206.   
  207. $total+=31;  
  208. case 7:  
  209.   
  210. $total+=30;  
  211. case 6:  
  212.   
  213. $total+=31;  
  214. case 5:  
  215.   
  216. $total+=30;  
  217. case 4:  
  218.   
  219. $total+=31;  
  220. case 3:  
  221.   
  222. $total+=28;  
  223. case 2:  
  224.   
  225. $total+=31;  
  226. }  
  227.   
  228. if($today["year"]%4 == 0 && $today["mon"]>2) $total++; //如果当年是闰年还要加一天  
  229.   
  230. $total=$total+$today["mday"]-1; //加当月的天数  
  231.   
  232. $flag1=0; //判断跳出循环的条件  
  233.   
  234. $j=0;  
  235. while ($j<=120){ //用农历的天数累加来判断是否超过阳历的天数  
  236.   
  237. $i=1;  
  238. while ($i<=13){  
  239.   
  240. $mtotal+=$everymonth[$j][$i];  
  241. if ($mtotal>=$total){  
  242.   
  243. $flag1=1;  
  244. break;  
  245. }  
  246.   
  247. $i++;  
  248. }  
  249.   
  250. if ($flag1==1) break;  
  251. $j++;  
  252. }  
  253.   
  254. if($everymonth[$j][0]<>0 and $everymonth[$j][0]<$i){ //原来错在这里,对闰月没有修补  
  255.   
  256. $mm=$i-1;  
  257. }  
  258.   
  259. else{  
  260.   
  261. $mm=$i;  
  262. }  
  263.   
  264. if($i==$everymonth[$j][0]+1 and $everymonth[$j][0]<>0) {  
  265.   
  266. $nlmon=$mmonth[0].$mmonth[$mm];#闰月  
  267.   
  268. }  
  269.   
  270. else {  
  271.   
  272. $nlmon=$mmonth[$mm].$mmonth[13];  
  273. }  
  274.   
  275. #计算所求月份1号的农历日期  
  276.   
  277. $md=$everymonth[$j][$i]-($mtotal-$total);if($md > $everymonth[$j][$i])  
  278.   
  279. $md-=$everymonth[$j][$i];  
  280. $nlday=$mday[$md];  
  281. $nowday=date("Y年n月j日 ").$weekday[$cur_wday]."
    "
    .$mten[$everymonth[$j][14]].$mtwelve[$everymonth[$j][15]]."年".$nlmon.$nlday;  
  282. echo "$nowday";  
  283.   
  284. ?>