Home > Backend Development > PHP Tutorial > Convert the string open_door to OpenDoor, and convert abc_bcd_cde to AbcBcdCde

Convert the string open_door to OpenDoor, and convert abc_bcd_cde to AbcBcdCde

WBOY
Release: 2016-07-25 09:08:33
Original
2143 people have browsed it
Convert the string open_door to OpenDoor, and convert abc_bcd_cde to AbcBcdCde
  1. 【html code】
  2. Convert the string open_door to OpenDoor, and convert abc_bcd_cde to AbcBcdCde
  3. < ;/form>
Copy code
  1. 【php code】/*Convert the string open_door to OpenDoor, and convert abc_bcd_cde to AbcBcdCde*/
  2. if($_POST[sub]=="Convert"){
  3. $string= $_POST[string];
  4. if(strstr($string,"_"))
  5. {
  6. $arr=explode("_",$string);
  7. //print_r($arr);
  8. for($i= 0;$i {
  9. $arr[$i]=ucfirst($arr[$i]);
  10. }
  11. $str=implode("",$arr);
  12. echo $str;
  13. }
  14. else
  15. {
  16. $array=str_split($string);
  17. for($i=0 ;$i {
  18. $str=ucfirst($array [$i]);
  19. if($str==$array[$i])
  20. {
  21. $array[$i]="_".strtolower($arrar[$i]);
  22. }
  23. }
  24. $ str1=implode("",$array);
  25. echo $str1;
  26. }
  27. }
  28. ?>
Copy code


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template