How to get & curren to display literally, and not as an HTML object

I am using php to view an XML file with a URL in it. The urls look something like this:

https://site.com/bacon_report?Id=1&report=1¤tDimension=2¶m=1

When I repeat the urls, "& curren" is displayed as "¤" (AKA # 164, A4 or currency symbol) and the links do not work. This happens, although there is no closing semicolon for it. What is the cleanest way to display & curren literally?

+4
source share
4 answers

Use php function urlencode function:

urlencode("https://site.com/bacon_report?Id=1&report=1&currentDimension=2&param=1"

displays

https%3A%2F%2Fsite.com%2Fbacon_report%3FId%3D1%26report%3D1%26currentDimension%3D2%26param%3D1 
+7
source

, , . , !

, & curren.

:

https://site.com/bacon_report?currentDimension=2&Id=1&report=1&param=1

:

https://site.com/bacon_report?Id=1&report=1&currentDimension=2&param=1
+8

- - "&". . XML , <, gt;, ",", .

https://example.com/bacon_report?Id=1&amp;report=1&amp;currentDimension=2&amp;param=1

.. HTML:

<a href="https://example.com/bacon_report?Id=1&report=1&currentDimension=2&param=1">WRONG - no escaping</a>
<a href="https://example.com/bacon_report?Id=1&amp;report=1&amp;currentDimension=2&amp;param=1">CORRECT - correct escape sequence</a>

, "& curren" HTML/XML - "& curren".

+5

, htmlentities, urlencode https%3A%2F%2Fexample.com%2Fbacon_report%3FId%3D1%26report%3D1%26currentDimension%3D2%26param%3D1

and when applying urldecode you will still have the & curren symbol where, as with htmlentities, the url comes out clean.
https://example.com/bacon_report?Id=1&report=1¤tDimension=2¶m=1

0
source

All Articles