pad every alternate character with a space

Posted on 2008-06-25
Last Modified: 2010-04-21

$myString = "BA5DSH1BXA5Q";

I want to pad every character with a space, so BA5DSH1BXA5Q
would become B A 5 D S H 1 B X A 5 Q

How can I do this please
Question by:NeilT
LVL 34

Accepted Solution

Beverley Portlock earned 500 total points
ID: 21865604
This should do it

$myString = "BA5DSH1BXA5Q";

echo ereg_replace("(.{1})", "\\1 ", $myString );

Author Closing Comment

ID: 31470539

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now