Switch character case, php

后端 未结 9 874
难免孤独
难免孤独 2020-12-05 11:48

How can I swap around / toggle the case of the characters in a string, for example:

$str = \"Hello, My Name is Tom\";

After I run the code

9条回答
  •  孤城傲影
    2020-12-05 12:27

    You'll need to iterate through the string testing the case of each character, calling strtolower() or strtoupper() as appropriate, adding the modified character to a new string.

提交回复
热议问题