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通过cookies获取远程网页的指定代码

复制代码 代码如下:function Steal($url, $post_data = ""){//$header[] = "Accept: text/vnd.wap.wml,*.*";...

用php获取远程图片并把它保存到本地的代码

<?php function GrabImage($url,$filename="") {   if($url==""):return&nb...

PHP常用的排序和查找算法

本文汇总了常见的php排序算法和查找,在进行算法设计的时候有不错的借鉴价值。现分享给大家供参考之用。具体如下: <?php /** * PHP最常用的四个排序方法及二...

PHP面向对象程序设计之命名空间与自动加载类详解

本文实例讲述了PHP面向对象程序设计之命名空间与自动加载类。分享给大家供大家参考,具体如下: 命名空间 避免类名重复,而产生错误。 <?php require_once...

将CMYK颜色值和RGB颜色相互转换的PHP代码

function hex2rgb($hex) { $color = str_replace('#','',$hex); $rgb = array('r' => hexdec(s...