Login or Sign Up
Logging in...
Remember me
Log in
Or
Sign Up
Forgot password or user name?
Log in with
Search in titles only
Search in PHP only
Search
Advanced Search
Forums
Product Launch
Updates
Today's Posts
Member List
Calendar
Home
Forum
Topic
PHP
Add whitespace between letters
Collapse
X
Collapse
Posts
Latest Activity
Photos
Page
of
1
Filter
Time
All Time
Today
Last Week
Last Month
Show
All
Discussions only
Photos only
Videos only
Links only
Polls only
Events only
Filtered by:
Clear All
new posts
Previous
template
Next
Lagon666
New Member
Join Date:
Jun 2009
Posts:
22
#1
Add whitespace between letters
Mar 5 '10, 09:05 PM
Does PHP has a function to add whitespace between letters?
Convert this "abc" to "a b c"?
Atli
Recognized Expert
Expert
Join Date:
Nov 2006
Posts:
5062
#2
Mar 5 '10, 09:13 PM
Hey.
Not as specific function, no (at least as far as I can tell), but you can easily achieve this by just looping through the string and adding a space after each letter.
Comment
Post
Cancel
jkmyoung
Recognized Expert
Top Contributor
Join Date:
Mar 2006
Posts:
2057
#3
Mar 5 '10, 09:19 PM
You could use
preg_replace("/(.)/i", "\${1} ", $str);
it should find each character, and replace each with a character plus space. You can then truncate the last space if you want.
edited..
made a slight correction.
Comment
Post
Cancel
Lagon666
New Member
Join Date:
Jun 2009
Posts:
22
#4
Mar 5 '10, 09:26 PM
Thanks
preg_split("//", $text) works too. But it might be slow.
Comment
Post
Cancel
zorgi
Recognized Expert
Contributor
Join Date:
Mar 2008
Posts:
431
#5
Mar 5 '10, 09:34 PM
maybe this:
echo wordwrap("abc", 1, " ", true);
Comment
Post
Cancel
Previous
template
Next
Working...
Yes
No
OK
OK
Cancel
👍
👎
☕
Comment