一个英文语句怎样把它的每个单词的字母顺序颠倒而单词顺序不变?_北京php培训

php面试题说明 :

例如:my name is fanglor  =》 ym eman si orlgnaf

php面试题的答案:

function restr ($str) 
{
	$str1 = explode (' ',$str);
	$str2 = '';
	$temp = '';
	for ($i=0;$i<count ($str1);$i++) 
	{
		$str2 .= $temp.strrev ($str1[$i]);
		$temp = ' ';
	}
	return $str2;
 
}

测试代码:

$str = "my name is fanglor ";
echo restr ($str);

打印结果:
ym eman si rolgnaf


Leave Your Comment

Your email will not be published or shared. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="">

*
请输入图片中的字符以验证你并非垃圾机器人. 点击图片收听验证码的语音版.
点击这里收听此验证码的语音版本