URL does not display symbols

Asked

Viewed 116 times

1

I have a website that sends a URL like this:

site.com.br/test.php?s=<p>texto</p>

The variable s is used by the page test.php to print a PDF.

But on the client’s computer it’s showing up like this:

site.com.br/test.php?s=%3Cp%3Etexto%3C/p%3E and printing does not work.

Any suggestions?

3 answers

2

This happened because it is necessary to encode the characters < and > for %3C and %3E respectively in order to be able to transmit them over the Internet.

A URL can only have ASCII characters so this encoding is required.

See this table: https://www.w3schools.com/tags/ref_urlencode.asp

I have already sent data with HTML tags by the GET method and the display has been performed normally, try to send the data by the POST method, if it does not post the form code and the data it receives to print.

1

This is called URL encoding and serves to avoid conflict between the contents URL with control characters. For example, URL parsers use the bar, /, to delimit the segments of the path, as well as using the question mark, ?, to start the query string and the keel, #, to start the fragment. If its contents have these characters the URL syntax may be impaired and thus misinterpreted.

For example, if I want to send the logical expression a & b = c through the URL and make:

https://localhost/query?s=a&b=c

To query string will be interpreted as s=a and b=c, which has no relation to our intention. Therefore it should be coded:

https://localhost/query?s=%3Fs%3Da%26b%3Dc

And in this way there will be no redundancy and therefore the URL will be interpreted correctly.

So if the print is being affected by the encoding, you need to review what you’re doing. Its trivial options would be: 1) Correctly decode the URL before using to generate the PDF; 2) Send the content through the HTTP request body and not the URL.

I would recommend the second option.

0

Urls do not support some special characters, which end up converted by the client (browser, application, etc.) at the time of making an HTTP request. The two Urls you reported are equivalent (after Encode-Decode), as you can see in this converter. The character conversion table is available at this link.

In PHP you should read your variable using the method urldecode.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.