shayan
shayan

Reputation: 361

xhtml special characters between different browsers

i am working on a cgi program , i am receiving an email address like this : [email protected] and storing it in a file. but some thing strange happens. when i use IE the '@' char , won't change and it is same in the file , but when i use chrome , '@' char ,changes to %40 and the only way to retrieve the '@' is to find %40 and replace it with '@'.am i coding wrong or chrome has problem?

to understand better : IE: [email protected] Chrome:someone%40site.com

and when i send information back to the browser , %40 doesn't change to @

Upvotes: 2

Views: 162

Answers (2)

shayan
shayan

Reputation: 361

the answer above is correct , just in make the topic richer i think this peace of code can be the function you use :

     int main()
{
    int number;
    string dataString="hi %40 c++ programmer %40 !";
    string transform;
    istringstream input;

    string::size_type location = dataString.find("%");
    while (location <string::npos)
    {
        transform = dataString.substr(location+1, 2);
        input.str(transform);
        input >> hex >> number;
        dataString.replace(location,3,1,static_cast<char>(number));
        location = dataString.find("%", location+1);
    }
    cout << dataString << endl;
}

Upvotes: 1

SteJ
SteJ

Reputation: 1541

It's IE that's doing it wrong in actual fact - You need to change the %xx code back to a character. In the case of %40 this would be ASCII no. 0x40 == 64 == '@'. You can't rely on it being ASCII, however, as unicode characters (such as accented letters) will also be similarly encoded.

Most languages like PHP and Python have a helper function to encode and decode these (PHP's is called url_encode() and url_decode()) - I've not used CGI on C++ for a long while, so not sure if there's a helper readily available or if you'll have to code your own - either way you should be prepared to decode url-encoded strings as all browsers will do this for some characters if not all (eg. %20 instead of a space is very common).

Hope this helps!

Upvotes: 3

Related Questions