<?php
$string = 'PrintHelloWorld';
$pattern = '/(?<!^)([A-Z])/';
$replacement = '_$1';
echo preg_replace($pattern, $replacement, $string);
?>