Most efficient way to delimit key

Say I have a string of 16 numeric characters (i.e. 0123456789012345) what is the most efficient way to delimit it into sets like : 0123-4567-8901-2345, in PHP?

Note: I am rewriting an existing system that is painfully slow.

Answers


Use str_split():

$string = '0123456789012345';
$sets = str_split($string, 4);
print_r($sets);

The output:

Array
(
    [0] => 0123
    [1] => 4567
    [2] => 8901
    [3] => 2345
)

Then of course to insert hyphens between the sets you just implode() them together:

echo implode('-', $sets); // echoes '0123-4567-8901-2345'

Need Your Help

UITableView -> How to load additional entry on scroll down?

ios uitableview load

I want to load my data on scroll down for my tableView.

Trouble with create_resources in Puppet 3.3.1

ubuntu ssh virtual-machine vagrant puppet

I'm using puppet 3.3.1 to provision a vagrant box running ubuntu 12.04 with hiera.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.