Conventions: Sentences are separated by a space, with a period as the end symbol.
Implementation ideas:
The string is split with the function explode (separator,string,limit), and the last member of the resulting data is split to cut off the symbol. A new array is received in reverse to the string and the period is replaced.
Code implementation:
<?php
/**
* Created by Phpstorm.
* User:administrator
* DATE:2016/9/25 0025
* time:22:29
*/
Strings that need to be reversed
$str = "I am a handsome boy";
$str _len=strlen ($STR);
Echo $str _len; the output is 20, confirm no problem.
Intercept. Character before substr (String,start,length)
$str =substr ($str, 0, $str _len-1);
echo $str; I am a handsome boy, the statement is no problem
Convert to Array
$str _arr=explode (' ', $str);
Var_dump ($str _arr);
Reverse reception
$str _str_new=array_reverse ($str _arr);
Array to String
$str _str_new_str=implode (', $str _str_new);
Echo ' before conversion: '. $str. ' <br/> '. ' After conversion: '. $str _str_new_str. ';
Effect:
PHP Learning Note: Enter a sentence to achieve the reverse output of the word