欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

PHP字符串word末字符大小写互换,字符串大小写

程序员文章站 2024-01-20 10:55:40
...

PHP字符串word末字符大小写互换,字符串大小写

要求

给出一个字符串如 “A journey of, a thousand 'miles' must can't \"begin\" with a single step.” ,通过 PHP 程序处理变成 “a journeY oF, A thousanD 'mileS' musT can'T "begiN" witH A singlE steP.”

注意:
1、每个单词最后的字符如果是大写就变成小写,如果是小写就变成大写。
2、需要考虑类似 can't 这种形式的转换。
3、标点符号(只考虑 , ' " . ;)不用变化。

参考算法

php

    function convertLastChar($str) {
        $markArr = array(", ", "' ", "\" ", ". ", "; ");
        $ret = "";
        for ($i = 0, $j = strlen($str); $i $j