Simple Soultion

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
eggoz
Forum Commoner
Posts: 43
Joined: Fri Dec 27, 2002 8:51 pm

Simple Soultion

Post 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&#1111;'Description']; ?>&item_number=<? echo $a_result&#1111;'Code']; ?>&amount=<? echo $a_result&#1111;'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.
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post 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.
eggoz
Forum Commoner
Posts: 43
Joined: Fri Dec 27, 2002 8:51 pm

Post 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.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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&#1111;'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&#1111;'Code']; ?>&amount=<?php echo $a_result&#1111;'Price']; ?>" target="_blank" class="nolink">Buy Now</a>
AFAIK encoded characters are automatically decoded.

Mac
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
eggoz
Forum Commoner
Posts: 43
Joined: Fri Dec 27, 2002 8:51 pm

At school

Post 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.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Try str_replace():

Code: Select all

$string = 'This_has_underscores_instead_of_spaces.';
$spaced_string = str_replace('_', ' ', $string);
Mac
Post Reply