php字符串按照单词进行反转的方法

yipeiwu_com6年前PHP代码库

本文实例讲述了php字符串按照单词进行反转的方法。分享给大家供大家参考。具体分析如下:

下面的php代码可以将字符串按照单词进行反转输出,实际上市现将字符串按照空格分隔到数组,然后对数组进行反转输出

<?php
$s = "Reversing a string by word";
// break the string up into words
$words = explode(' ',$s);
// reverse the array of words
$words = array_reverse($words);
// rebuild the string
$s = implode(' ',$words);
print $s;
?>

输出结果如下:
word by string a Reversing

希望本文所述对大家的php程序设计有所帮助。

相关文章

thinkphp 手机号和用户名同时登录

话不多说,请看代码: //在注册时用户名不能是纯数字, 防止一个人的用户名和另一个人的手机号相同 public function Login(){ if (IS_AJAX) {...

Windows2003下php5.4安装配置教程(Apache2.4)

Windows2003下php5.4安装配置教程(Apache2.4)

直接配置php一直使用如同《【php】本地开发环境的部署与helloworld》的一键傻瓜包,被批为极度不专业,关键是这些一键傻瓜包LAMP的版本不好控制,端口什么的也不好调。曾经在Li...

phpmyadmin中禁止外网使用的方法

本文实例讲述了phpmyadmin中禁止外网使用的方法。分享给大家供大家参考。具体方法如下: 首先,在phpmyadmin文件夹中找到 phpmyadmin.conf 在文件中能看到如下...

使用ThinkPHP自带的Http类下载远程图片到本地的实现代码

Http类在目录ThinkPHP/Lib/ORG/Net下面。接下来看看是如何调用的。 复制代码 代码如下: <?php import("Com.Buyback.QueryAmaz...

php删除二维数组中的重复值方法

实例如下所示: //二维数组去掉重复值 public function a_array_unique($array){ $out = array(); foreach (...