Retaining spaces in form text

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 1
Joined: Thu Mar 29, 2018 9:56 am

Thu Mar 29, 2018 10:10 am

I am an editor faced with editing text in which the style requirements say there should be TWO blank spaces between sentences. So I was going to write a straightforward PHP routine with an HTML form to check for one-space separations so that I could mark and correct them. Unfortunately, I discovered that the form submission process automatically changes double spaces to single spaces, so it's impossible for me to separate the "real" single spaces in the text from the ones that the PHP submission process created.

I don't need help with PHP., though. I'm just trying to figure out how I can submit data through a form such that the extra spaces in the text are retained (after I "ingest" the text into my PHP code using $_REQUEST). Right now if I create, say, $Text=$_REQUEST in my code, the Text variable will automatically have no double spaces, no matter how many double spaces the original text might have had.

Thanks in advance for any ideas. I've looked online but almost everyone is talking about getting RID of double spaces, not retaining them.

User avatar
php-forum Fan User
php-forum Fan User
Posts: 775
Joined: Mon Feb 22, 2016 5:52 pm

Thu Mar 29, 2018 12:07 pm

I'm not sure as I fully understand your question, however, HTML is supposed to ignore excess whitespace and reduce it to a single space.

If you mean that there should be two spaces after a full stop, then what you could look at doing is using JavaScript to change one of the spaces to the html entity   before submission; this stands for Non-Breaking SPace; it does bring with it some potential problems and may cause unwanted breaking so there is also   or   depending on how wide a space you want.

New php-forum User
New php-forum User
Posts: 17
Joined: Thu Aug 17, 2017 3:37 am

Tue Apr 03, 2018 2:36 am

I discovered that the form submission process automatically changes double spaces to single spaces ...
I have never come across the HTTP Form submission process changing the content submitted by the user. These days, it's possible that there's some clever, client-side Javascript "stuff" being "helpful" and getting in your way, but raw HTML input controls just won't do this.

I have come across HTML rendering multiple spaces so that they look like one, because that's just what it does.

Even so, you're still receiving a full-stop followed by a space, which you want to replace with a full-stop and two spaces. That should be simple enough.
Phill W.

Post Reply