Home >Backend Development >PHP Tutorial >在再简化代码需求~~

在再简化代码需求~~

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-23 14:39:581057browse

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

这代码还能简化吗?变量有点多了 。


回复讨论(解决方案)

如果你的php版本在5.4及5.4以上的话,你的这段代码
$b=explode("/",DEDEROOT);
$c=$b['1'];
可以简化为
$c=explode("/",DEDEROOT)[1];

list($b,$c,$d)=explode("/",DEDEROOT);$a ='/reg/resetpw.php?p='.base64_encode($row['userid'].".".md5($row['userid']."+".$row['pwd']));$a = "<a href='$a'>$c.$a</a>";

如果你的php版本在5.4及5.4以上的话,你的这段代码
$b=explode("/",DEDEROOT);
$c=$b['1'];
可以简化为
$c=explode("/",DEDEROOT)[1];
饿  php版本没有达到要求。
没别的办法?

list($b,$c,$d)=explode("/",DEDEROOT);$a ='/reg/resetpw.php?p='.base64_encode($row['userid'].".".md5($row['userid']."+".$row['pwd']));$a = "<a href='$a'>$c.$a</a>";

谢谢

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

这样呢

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

这样呢
好像还是编译不过来。提示错误了

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

这样呢
那个list函数支持~

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

这样呢
可以了  sorry 我刚才忘记保存了 感谢

不要太过于简化,因为那会导致PHP 版本兼容性??

???量就少了

$x = md5($row['userid']."+".$row['pwd']);$x = base64_encode($row['userid'].".".$x);//print_r($x);die;$b=explode("/",DEDEROOT);$b = "<a href='/reg/resetpw.php?p={$x}'>{$b['1']}./reg/resetpw.php?p={$x}</a>";echo '<pre class="brush:php;toolbar:false">',var_dump($b),'
';

strtok(DEDEROOT, "/");$a ='/reg/resetpw.php?p=' . base64_encode($row['userid'].".".md5($row['userid']."+".$row['pwd']));$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