473,545 Members | 524 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Add whitespace between letters

22 New Member
Does PHP has a function to add whitespace between letters?

Convert this "abc" to "a b c"?
Mar 5 '10 #1
4 8313
Atli
5,058 Recognized Expert Expert
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.
Mar 5 '10 #2
jkmyoung
2,057 Recognized Expert Top Contributor
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.
Mar 5 '10 #3
Lagon666
22 New Member
Thanks
preg_split("//", $text) works too. But it might be slow.
Mar 5 '10 #4
zorgi
431 Recognized Expert Contributor
maybe this:

echo wordwrap("abc", 1, " ", true);
Mar 5 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2137
by: Wolfgang Jeltsch | last post by:
Hello, it is often convenient to insert whitespace into an XML document in order to format it nicely. For example, take this snippet of a notional DocBook XML document: <para> This is a longer paragraph. With <wordasword>longer</wordasword> I mean that it contains more than one sentence.
4
6111
by: Dwayne Epps | last post by:
I've created a function that checks form fields that only will have letters. This is the script: <script type="text/javascript" language="javascript"> function validateString(field, msg, min, max) { if (!min) { min = 1 } if (!max) { max = 65535} if (!field.value || field.value.length < min || field.value.max > max) { alert(msg);...
7
5913
by: bc9am | last post by:
Hi, I'm having problems with the <form> tag creating some unwanted whitespace. I did a search on this forum and came across this link: http://www.cs.tut.fi/~jkorpela/forms/extraspace.html Which gives a semi-work around to the problem (uses CSS). This however does not work in Netscape 4 browsers.
1
4225
by: | last post by:
Hi, I have a Regular Expression that will match the format a user provides in a textbox. Ex. Brown,Joe in the textbox I would like the expression to have both whitespace and non-whitespace options after the comma.
0
2228
by: Shan Plourde | last post by:
Hi everyone, I have been using various regular expressions with the ASP.NET RegularExpressionValidator for quite some time. In general it works very well. One of the common regex's that I use follows: ValidationExpression = "^\d{0,3}(\.\d{0,4})?$" The purpose of this one is to validate that numeric values input follow the syntax...
3
2617
by: David Pratt | last post by:
Hi. I am splitting a string on a non whitespace character. One or more whitespace characters can be returned as items in the list. I do not want the items in the list that are only whitespace (can be one or more characters of whitespace) and plan to use string.strip on those items that are not only whitespace (to remove any whitespace from...
20
5187
by: ilyas | last post by:
I have some html which consists of a paragraph tag and some text inside it What I want to do is to maintain the whitespace in this paragrpah so that it appears exactly like that in the browser, without any of the spaces removed. How can I do this?
12
1683
by: gil | last post by:
I would like to display a Union Collective Agreement in HTML format and keep it as true as possible to the pdf version. The document uses Article Numbers such as 1.01, 1.02 which are not available in list numbering. but does use sublists with alpha and roman numbering that should be easy enough to code. What I want to do, is code to this...
9
2545
by: amattie | last post by:
Does anyone have any idea on how I can strip the extra whitespace in the XML that shows up when I receive a response from an ASP.NET 2.0 webservice? This has been discussed before, but no one has ever come up with a good answer to what seems like such a common question. ...
5
1731
by: tim | last post by:
I am new to Regular Expressions and need some assistance with my Zip Code field validator. I am currently using the following regex to validate a zip code: ^(\d{5}(( |-)\d{4})?)|(\d( |-)\d\d)$ I would like to account for any number of leading and trailing whitespace characters but am not sure how to do so. Thanks in advance for your...
0
7455
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7802
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7410
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7743
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5959
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5319
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4940
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1867
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1010
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.