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程序设计有所帮助。

相关文章

PHP的命令行命令使用指南

 当用户打开php页面时,服务端便执行PHP的命令并将执行结果发送至用户的浏览器中,这类似于ASP和CoildFusion,PHP可以运行在WINDOWS和多种版本的UNIX上...

php中__destruct与register_shutdown_function执行的先后顺序问题

根据php手册的解析。 __destruct是 析构函数会在到某个对象的所有引用都被删除或者当对象被显式销毁时执行。 而register_shutdown_function是 Regis...

PHP如何通过表单直接提交大文件详解

PHP如何通过表单直接提交大文件详解

前言 我想通过表单直接提交大文件,django 那边我就是这么干的。而对于 php 来说,我认为尽管可以设置最大上传的大小,但最大也无法超过内存大小,因为它无法把文件内容都放到 php:...

php数据库配置文件一般做法分享

config.php文件: 复制代码 代码如下: <?php $db_name="test"; $db_username="root"; global $db_password;...

PHP容器类的两种实现方式示例

本文实例讲述了PHP容器类的两种实现方式。分享给大家供大家参考,具体如下: 通过魔术方法实现 class class MagicContainer{ private $ele;...