J
J
jasonOk2015-11-01 10:23:31
PHP
jasonOk, 2015-11-01 10:23:31

Space error?

Foreword
Comments are added on the site via ajax ie. is being sent to the server.
You can write tags <p> <b> <div>and the like; tinyMCE is used (filtering extra tags with jevix ). The comments themselves work fine and are added, but just recently I noticed a strange bug.
The essence of the problem
And here's the thing: I enter a simple text "123 123" it is sent as <p>123 123</p>, BUT if there is more than one space in a row, then everything after these spaces is cut off.

It turns out:
let's say I send the text variable <p>123 123</p>(2 spaces in the middle)
for the test on the server I made only a few lines

if(!empty($_POST['text'])){

echo $_POST['text'];

}else echo 'error';

echoBut it outputs to the console <p>123(cuts off the source text)
It also does not work at all <p> 123</p>(a space at the very beginning).
It seems like the error is related to the tag <p>- supposedly it removes the repetition of spaces, but ... I still think not.
So how can this problem be solved?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
N
NKros, 2015-11-01
@NKros

Check in your browser's developer tools what exactly is being sent with post.
Most likely, your spaces break the line at this point and everything else is simply not sent.

A
Alexey Lebedev, 2015-11-01
@swanrnd

Replace a lot of all spaces with one.

$text = " one   two    three ";
$text = preg_replace('| +|', ' ', $text);
var_dump($text);

V
Vladislav Startsev, 2015-11-01
@esvlad

It is unlikely that the problem is with the tag, how can a tag remove spaces at all, right, no way.
Alternatively, a bug in Jevix. Look in its settings.
In general, you can use Tiny without this plugin, you just need to configure it normally.

A
Anton Tikhomirov, 2015-11-01
@Acuna

You didn’t write what kind of engine the site has, samopis? Often they filter the contents of the $_GET array, removing everything unnecessary from it, so that injections into it do not pop. Perhaps under one and $_POST you filter, but somehow crooked. Or some other plug-in intercepts and cuts off everything. But something must definitely break it, it cannot break itself, superglobals are just arrays, they just contain data that scripts already use. Enter your code at the very beginning of the site (right in index.php), if a clear value is displayed, then lower it further and check again until you find what breaks. The only way. Who is easy now?

R
RozenZwei, 2021-01-27
@RozenZwei

This is a feature of POST - spaces break off the body of the message.
To avoid this - wrap in encodeURIComponent().
It makes the message continuous.
Those. when sending from js, do not but And you will be happy.)
data: "message=" + message
data: "message=" + encodeURIComponent(message)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question