Home > Backend Development > PHP Tutorial > PHP面试有关问题考卷03

PHP面试有关问题考卷03

WBOY
Release: 2016-06-13 13:03:16
Original
996 people have browsed it

PHP面试问题考卷03
4、使用哪些工具进行版本控制?
SVN

5、如何实现字符串翻转?

$str = "Holle World!";

echo strrev($str);//!dlroW elloH

echo t_strrev($str);//!dlroW elloH


function t_strrev($str) {
	$n_str = '';
	for ($i=strlen($str); $i>=0; $i--) {
		$n_str .= $str[$i];
	}
	return $n_str;
} // end func
Copy after login


这样是没问题,不过应该不是这样的。

解决中文乱码方法:
/**
* 反转utf8的字符串,使用mb开头的函数
* @param string $str
* @return string
*/
function t_strrev($str) {
	$len = mb_strlen($str, 'UTF-8');
    $string = '';
    for ($i = $len - 1; $i >= 0; $i--) {
       $string .= mb_substr($str, $i, 1, 'UTF-8');
    }
    return $string;
} // end func
Copy after login
Related labels:
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