문제

I have a string like "kp_o_zmq_k" and I need to covert it to "kpOZmqK" where I need to convert all letters connected to the right of the underscore(o,z,k in this case) to uppercase.

도움이 되었습니까?

해결책 2

Try with preg_replace_callback function in php.

$ptn = "/_[a-z]?/";
$str = "kp_o_zmq_k";
$result = preg_replace_callback($ptn,"callbackhandler",$str);
// print the result
echo $result;

function callbackhandler($matches) {
    return strtoupper(ltrim($matches[0], "_"));
}

다른 팁

<?php
function underscore2Camelcase($str) {
  // Split string in words.
  $words = explode('_', strtolower($str));

  $return = '';
  foreach ($words as $word) {
    $return .= ucfirst(trim($word));
  }

  return $return;
}
?>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top