Page 1 of 2

Why doesn't it show?

Posted: Mon Feb 17, 2003 6:51 pm
by eggoz
I have this link,
<a href="https://www.paypal.com/cart/add=1&busin ... item_name="<? echo $a_result['Description']; ?>"&item_number=<? echo $Code; ?>&amount=<? echo $Price; ?>" target="_blank" class="nolink">Buy Now</a>

When you try to view it on a webpage, all I see is:https://www.paypal.com/cart/add=1&busin ... item_name=

Why won't the rest of the link work?

Posted: Mon Feb 17, 2003 7:33 pm
by Aero
i think its cause after name= you have a " that probaly stops the link
<a href="https://www.paypal.com/cart/add=1&busin ... item_name=<? echo $a_result['Description']; ?>&item_number=<? echo $Code; ?>&amount=<? echo $Price; ?>" target="_blank" class="nolink">Buy Now</a>

Posted: Mon Feb 17, 2003 8:11 pm
by eggoz
I know. that " has to be there in order to be able to pass values to paypal correctly.

Posted: Mon Feb 17, 2003 8:41 pm
by Aero
maybe instead of " try ' to pass the values correctly, not sure if it would work

Posted: Mon Feb 17, 2003 8:45 pm
by eggoz
Not sure what you mean.

Posted: Mon Feb 17, 2003 8:48 pm
by Aero
nm that wont work, dont know how u can do it

Posted: Mon Feb 17, 2003 8:54 pm
by eggoz
Yeah, been stuck with this problem for a while now. Can not figure this one out. Where is everyone? Usually quite a few people on.

Posted: Mon Feb 17, 2003 9:15 pm
by Stoker
i don't know the paypal system, but I am pretty sure you would need to encode @ and " in order to use with a url.. use something like

<a href="protocol://server/dir/file?var=<?php echo urlencode('"any stuff here"'); ?>&other=anyplaintext">

Nope.

Posted: Mon Feb 17, 2003 9:49 pm
by eggoz
There is certain ones that need to be encoded. Pretty much all special characters need to be encoded, except the /.

For example, I can use %, I need to use %28 instead. Which means it needs to be encoded.

Yet, When I use / it works fine. But when I use %2F (this is what paypal tries to convert a / to), it won't work.

I don't know what to do. If I encode, then &,%,$ won't work, but / will. If I don't encode, then ? will work, but &,%,$ will not.

Posted: Mon Feb 17, 2003 9:52 pm
by Stoker
you have to encode quotes anyway, they will terminate your href...

Idea?

Posted: Mon Feb 17, 2003 10:02 pm
by eggoz
Is there anyway to tell it when you click on the link, to replace / with / ? Sounds dumb, but... $spaced_string = str_replace('/', '/', $description); would replace / with / instead of converting it to %2F which is what is happening now. But it would have to be done after I click on the link. Is this possible?

Posted: Tue Feb 18, 2003 2:24 am
by twigletmac
You can use urlencode() to encode a string and then use str_replace() to replace the parts that you need to.

Code: Select all

$encoded = urlencode($var);
$encoded_sortof = str_replace('%2F', '/', $encoded);
Mac

Posted: Tue Feb 18, 2003 3:20 am
by eggoz
I thought about that. The problem is, / is converted into %2F after I click on the link. I'm basiclly telling it to change all %2F that don't exsists because on the page they still appear as /. Follow me?

I could not encode anything, and tell it when it comes across ( )or %, to convert them to %28 (or corosponding number).

Here's what I came up with (didn't work):

Code: Select all

<?php 

$Description = $a_result&#1111;'Description']; 

foreach( $Descrption as $temp ) &#123;
	$Description_change = str_replace('/', '%28', $Description);
&#125;
foreach( $Descrption as $temp ) &#123;
	$Description_change = str_replace('"', '%25', $Description);
&#125;
?>
Click on BUY NOW.
I tried this code, as you can see, the item_name has disappeared instead of converting it in %25item_name%25. Any ideas?

Posted: Tue Feb 18, 2003 4:44 am
by twigletmac
Have you tried something like:

Code: Select all

<?php
$description = urlencode($a_result['Description']);
$description = str_replace('%2F', '/', $description);
?>
<a href="https://www.paypal.com/cart/add=1&business=information@aardvarksafety.com&item_name="<? echo $description; ?>"&item_number=<? echo $Code; ?>&amount=<? echo $Price; ?>" target="_blank" class="nolink">Buy Now</a>
It appears to work for me.

Mac

Posted: Tue Feb 18, 2003 4:51 am
by twigletmac
Oh and using arrays you can easily setup the various characters you would like to not be encoded. BTW, the encoding is done using urlencode() - it does not happen when you click on the link, it is just that it is only shown in the location bar on the browser.

Code: Select all

<?php 
$decode['from'] = array('%2F', '%28', '%29');
$decode['to'] = array('/', '(', ')');

$description = urlencode($a_result['Description']); 
$description = str_replace($decode['from'], $decode['to'], $description); 
?>
For more information:
http://www.php.net/urlencode
http://www.php.net/str_replace

Mac