anand
anand

Reputation: 11339

amp in xml getting comverted to "&"

I am creating one url and adding & to that url.

eg http://xyzc.com/abc.php?arg1=value1&arg2=value2

Now I am adding this url to xml .

I am creating xml via tinyxml in c++ and also tried creating same xml in php.

After creating the xml I found out that "&" is converted to "&"

Is it okay for "&" to get converted to "&"? Why is this happening ? And what could be the possible fix for this?

$strUrl ="http://xyzc.com/abc.php?";
$strUrl .="arg1=".$value1;
$strUrl .="&arg2=".$value2;

The output is coming as

http://xyzc.com/abc.php?arg1=10&arg2=100

Upvotes: 1

Views: 1763

Answers (1)

SLaks
SLaks

Reputation: 887877

XML has a feature called a character reference (&thingy;)

Therefore, all raw & characters must be escaped as &
This is a pre-defined character reference equivalent to & (amp stands for ampersand).

Leaving an unescaped & will create invalid XML.

Note that raw < characters must also be escaped as &lt; (lt stands for less-than).

Upvotes: 3

Related Questions