Home  >  Article  >  Backend Development  >  在再简化代码需求~该如何解决

在再简化代码需求~该如何解决

WBOY
WBOYOriginal
2016-06-13 11:45:49945browse

在再简化代码需求~~

$x = md5($row['userid']."+".$row['pwd']);<br />$str = base64_encode($row['userid'].".".$x);<br />//print_r($str);die;<br />$b=explode("/",DEDEROOT);<br />$c=$b['1'];<br />$a ='/reg/resetpw.php?p='.$str;<br />$a = "<a href='$a'>$c.$a</a>"; 

这代码还能简化吗?变量有点多了 。
------解决方案--------------------
如果你的php版本在5.4及5.4以上的话,你的这段代码
$b=explode("/",DEDEROOT);
$c=$b['1'];
可以简化为
$c=explode("/",DEDEROOT)[1];
------解决方案--------------------
<br />list($b,$c,$d)=explode("/",DEDEROOT);<br />$a ='/reg/resetpw.php?p='.base64_encode($row['userid'].".".md5($row['userid']."+".$row['pwd']));<br />$a = "<a href='$a'>$c.$a</a>";<br />

------解决方案--------------------
不要太过于简化,因为那会导致PHP 版本兼容性問題
------解决方案--------------------
strtok(DEDEROOT, "/");<br />$a ='/reg/resetpw.php?p=' . base64_encode($row['userid'].".".md5($row['userid']."+".$row['pwd']));<br />$a = "<a href='$a'>".strtok("/")."$a</a>";
 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn