Home > Backend Development > PHP Tutorial > PHP的substr函数如何完全模拟ASP的right函数

PHP的substr函数如何完全模拟ASP的right函数

WBOY
Release: 2016-06-23 14:09:52
Original
981 people have browsed it

有人说substr能完全取代ASP的right函数
//right (x)
substr($str,-x); 

但如果x=0时,就完全不能取代了,有什么办法可以当x=0时,也用substr取代吗


回复讨论(解决方案)

如果偏移是 0 就返回空串

function right($s, $n) {  return $n ? substr($s, -$n) : '';}
Copy after login

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template