Ququn Calambur
Ququn Calambur

Reputation: 3

Encoding string in PHP

I currently working on PHP and at some part of code I generate URL string. I set the GET parameter to currencyCode. But before I add &. So, at result I must get &currencyCode but get ¤cyCode.

How do I fix it?

Upvotes: 0

Views: 145

Answers (2)

Marcin Nabiałek
Marcin Nabiałek

Reputation: 111829

You need to create url this way using urlencode() function:

<?php

   echo 'http://example.com/'.urlencode('&currencyCode');

I also think that your main problem is with displaying it. You should use:

echo htmlspecialchars('&currencyCode');

to display it.

Otherwise it seems browser change the first part of this string into: &curren; entity so you get something like that &curren;cyCode and what makes you have display &curren; symbol what is ¤ and the rest of string cyCode

Upvotes: 2

Utkarsh Dixit
Utkarsh Dixit

Reputation: 4275

You should use urlencode() function in php to encode the url. Your code should look like this

<?php
echo 'http://yoursitename.com/'.urlencode('&currencyCode');

Upvotes: 1

Related Questions