Link to home
Start Free TrialLog in
Avatar of fgict
fgict

asked on

urlencode showing + instead of %20

New to PHP, so please bare with me...

I am trying to display a variable with "%20" instead of space, but code is just producing a "+" symbol

Example I have a product code "80000 #ABC" and I need to display it as "80000%20%23ABC" to ensure some of my javascript code works correctly
My current code <?= urlencode($product['prod_code']) ?> just produces "80000+%23ABC"
SOLUTION
Avatar of marchent
marchent
Flag of Bangladesh image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fgict
fgict

ASKER


Ok, Looks like that code will work, however, in my example i'm still having problems, the button for Tell a Friend shows the correct code now:

<li class="send"><a href="javascript:open_popup('80000%20%23ABC')" onMouseOver="self.status='Send to a friend'; return true;">Send to a friend</a></li>
It then loads the sendtoafriend.php popup window with path /sendtoafriend.php?prod_code=80000#ABC perhaps the javascript is throwing it off? see code on product page here:
<script language="JavaScript" type="text/javascript">
<!--
function open_popup(product_code) {
    window.open("sendtoafriend.php?prod_code="+product_code,"Send_to_a_friend","menubar=no,width=440,height=380,toolbar=no");
}
//-->
</script>

Or maybe it is the Send to a Friend Form (sendtoafriend.php) itself, see code on top of this page here:
<?php
// Record what product we're linking to.
$product_code = rawurlencode($_GET['prod_code']);
?>

you code is working perfectly with me.
<script language="JavaScript" type="text/javascript">
<!--
function open_popup(product_code) {
   window.open("sendtoafriend.php?prod_code="+product_code,"Send_to_a_friend","menubar=no,width=440,height=380,toolbar=no");
}
//-->
</script>
<li class="send"><a href="javascript:open_popup('80000%20%23ABC')" onMouseOver="self.status='Send to a friend'; return true;">Send to a friend</a></li>

Open in new window