Why doesn't it show?
Moderator: General Moderators
Why doesn't it show?
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?
<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?
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>
<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>
Nope.
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.
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.
Idea?
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?
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
You can use urlencode() to encode a string and then use str_replace() to replace the parts that you need to.
Mac
Code: Select all
$encoded = urlencode($var);
$encoded_sortof = str_replace('%2F', '/', $encoded);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):
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?
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ї'Description'];
foreach( $Descrption as $temp ) {
$Description_change = str_replace('/', '%28', $Description);
}
foreach( $Descrption as $temp ) {
$Description_change = str_replace('"', '%25', $Description);
}
?>I tried this code, as you can see, the item_name has disappeared instead of converting it in %25item_name%25. Any ideas?
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Have you tried something like:
It appears to work for me.
Mac
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>Mac
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
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.
For more information:
http://www.php.net/urlencode
http://www.php.net/str_replace
Mac
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);
?>http://www.php.net/urlencode
http://www.php.net/str_replace
Mac