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整合七牛实现上传文件

七牛支持抓取远程图片 API,用 access_key + secret_key + url 生成 access_token, 把 access_token 加在 header 里,然后...

PHP中localeconv()函数的用法

PHP中localeconv()函数的用法

PHP localeconv() 函数 实例 查找美国本地的数字格式化信息: <?php setlocale(LC_ALL,"US"); $locale_info =...

php微信支付之APP支付方法

本文实例讲述了微信开放平台移动应用集成微信支付功能。分享给大家供大家参考。具体分析如下: WechatAppPay文件代码如下: 复制代码 代码如下: <?php name...

php判断对象是派生自哪个类的方法

本文实例讲述了php判断对象是派生自哪个类的方法。分享给大家供大家参考。具体实现方法如下: <?php $th = new Thread; //创建新对象 if (...

统计PHP目录中的文件数方法

代码示例如下: <?php $folderPath = "upload/"; $countFile = 0; $totalFiles = glob($folderPat...