/    Sign up×
Community /Pin to ProfileBookmark

Inserting Character into String?

Hi,

Maybe someone could jog my memory, I’m sure I’ve done this before, although a few years ago.

I have a list of mobile numbers pulled from AD/LDAP, ($info[$i][“mobile”][0]) that are all in a single long string, i.e. 07812345678, I’d like to insert a whitespace at the 5th character, to make it more user friendly, so it looks like 07812 345678.

Isn’t there a function, where you can insert a character a certain number of positions either from left or right of the string? I’m sure I used something like this back in PHP4, but maybe my memory isn’t what it used to be!

Is there such a function, or am I just imagining it? ?

Ben

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@MindzaiJan 19.2009 — Try:

[code=php]$string = substr_replace($string, ' ', 4, 0);[/code]
×

Success!

Help @bjblackmore spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.9,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...