Page 1 of 1
Simple Soultion
Posted: Wed Feb 12, 2003 11:13 pm
by eggoz
When passing (click on Buy Now)values on this
page, you can see how the % causes a problem. Paypal has no problems with spaces, but %, /, or )( causes a problem.
Here is my code..
Code: Select all
a href="https://www.paypal.com/cart/add=1&business=information@aardvarksafety.com&item_name=<? echo $a_resultї'Description']; ?>&item_number=<? echo $a_resultї'Code']; ?>&amount=<? echo $a_resultї'Price']; ?>" target="_blank" class="nolink">Buy Now</a>
I know when printing html values you can simply use a / in front of quotations, but I don't have any here. How can this be accomplished? Thanks.
Posted: Thu Feb 13, 2003 5:36 am
by Wayne
Have you tried encoding the parameters passed to the url??? this will replace the % sign with a value that can be passed through the browser with causing these problems.
Posted: Thu Feb 13, 2003 7:40 am
by eggoz
I'm sorry, I don't follow you. I'm not the best with php. How can I encode it. Also it has to be a %. Everything is read from a database before passing values to Paypal.
Posted: Thu Feb 13, 2003 7:58 am
by twigletmac
You can use the
urlencode() function to ensure that special characters are properly encoded in the URL:
Code: Select all
<?php
$description = urlencode($a_resultї'Description']);
?>
a href="https://www.paypal.com/cart/add=1&business=information@aardvarksafety.com&item_name=<?php echo $description; ?>&item_number=<?php echo $a_resultї'Code']; ?>&amount=<?php echo $a_resultї'Price']; ?>" target="_blank" class="nolink">Buy Now</a>
AFAIK encoded characters are automatically decoded.
Mac
Posted: Thu Feb 13, 2003 8:00 am
by twigletmac
Just tested replacing the % in your URL with %25 - the encoded version of the percent sign and it seemed to work fine.
Mac
At school
Posted: Thu Feb 13, 2003 9:40 am
by eggoz
Thanks. I'm at school right now and have no access to ftp, so I can't test it. But i'll take your word for it and test it later tonight. Thanks again.
Also, is there anyway when the php file is being read by the server, to convert one character to another? For example, I have on some pages _ which I would like to convert to a space.
Posted: Fri Feb 14, 2003 2:13 am
by twigletmac
Try
str_replace():
Code: Select all
$string = 'This_has_underscores_instead_of_spaces.';
$spaced_string = str_replace('_', ' ', $string);
Mac