Why doesn't it show?

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

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

Why doesn't it show?

Post 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?
Aero
Forum Newbie
Posts: 7
Joined: Fri Feb 14, 2003 1:58 pm

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

Post by eggoz »

I know. that " has to be there in order to be able to pass values to paypal correctly.
Aero
Forum Newbie
Posts: 7
Joined: Fri Feb 14, 2003 1:58 pm

Post by Aero »

maybe instead of " try ' to pass the values correctly, not sure if it would work
eggoz
Forum Commoner
Posts: 43
Joined: Fri Dec 27, 2002 8:51 pm

Post by eggoz »

Not sure what you mean.
Aero
Forum Newbie
Posts: 7
Joined: Fri Feb 14, 2003 1:58 pm

Post by Aero »

nm that wont work, dont know how u can do it
eggoz
Forum Commoner
Posts: 43
Joined: Fri Dec 27, 2002 8:51 pm

Post 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.
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

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

Nope.

Post 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.
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

Post by Stoker »

you have to encode quotes anyway, they will terminate your href...
eggoz
Forum Commoner
Posts: 43
Joined: Fri Dec 27, 2002 8:51 pm

Idea?

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

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

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

Post 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
Post Reply