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

相关文章

MongoDB在PHP中的常用操作小结

$mongodb = new Mongo(); //$connection = new Mongo( "$dburl:$port" ); // connect to a remote h...

关于时间计算的结总

php中计算时间差有时候是件很麻烦的事!  不过我相信任何语言,只要撑握了其中规率就能找到办法,绝对是化腐朽为神奇的。  工作中经常要进行日期计算,下面总结几个工作中...

php echo()和print()、require()和include()函数区别说明

1.echo和print的区别 PHP中echo和print的功能基本相同(输出),但是两者之间还是有细微差别的。echo输出后没有返回值,但print有返回值,当其执行失败时返回fla...

PHP开发中的错误收集,不定期更新。

Fatal error: Non-static method Conn::__construct() cannot be called statically in /file.php 没...

PHP OPCode缓存 APC详细介绍

PHP OPCode缓存 APC详细介绍

APC的介绍 The Alternative PHP Cache (APC) is a free and open opcode cache for PHP. Its goal is t...