Hi! Could we please enable some services and cookies to improve your experience and our website?
Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code
<?php
$tests = array(
'LocalBusiness' => 'Local Business',
'CivicStructureBuilding' => 'Civic Structure Building',
'getUserMobilePhoneNumber' => 'Get User Mobile Phone Number',
'bandGuitar1' => 'Band Guitar 1',
'band2Guitar123' => 'Band 2 Guitar 123',
'CustomerIDWithSomeOtherJETWords' => 'Customer ID With Some Other JET Words',
'noOneIsMightierThanI' => 'No One Is Mightier Than I',
'USAIsNumber4' => 'USA Is Number 14',
);
foreach ($tests AS $input => $expected) {
$output = ucwords(
preg_replace(
//array('/(?<=[^A-Z])([A-Z])/', '/(?<=[^0-9])([0-9])/'),
'/([A-Z]{2,}?(?=[A-Z][a-z]+|[^A-Z])|[A-Z]?[a-z]*(?=[^a-z])|\d+(?=\D+))\K/',
' ',
$input
)
);
echo $output .' : '. ($output == $expected ? 'PASSED' : 'FAILED') . PHP_EOL;
}