urlencode() strings for mailto:subject= with dash characters that can be properly decoded

StackOverflow https://stackoverflow.com/questions/21124063

  •  28-09-2022
  •  | 
  •  

Question

I have a string, for example "2013 International Truck – XZ1234" which I need to urlencode() and include in a mailto subject= in a way that will be properly decoded. I have tested this in the following way:

$encodedstring = urlencode("mailto:info@something.com?subject=2013 International Truck – XZ1234")
<a href="<?php $encodedstring ?>">Email Us</a>

The link will then look like this:

<a href="mailto:info@southlandit.com?subject=2013+International+Truck+%26%238211%3B+XZ1234">Email Us</a>

The subject then is decoded and displayed in the subject input field to look like this: (this has been tested in Gmail)

2013 International TerraStar Truck &#8211; NT2031

Is there an alternative to urlencode() or some other way to encode this string so that all characters, including dashes are properly decoded in mail clients?

Was it helpful?

Solution

Your string is being double encoded. %26%238211%3B is the encoded form of &#8211;, which is the encoded form of the dash. Trace your code execution to see where it is being encoded twice.

OTHER TIPS

you can use following to remove special formatting..

remove_filter( ‘the_title’ , ‘wptexturize’ );

remove_filter( ‘the_content’ , ‘wptexturize’ );

remove_filter( ‘the_excerpt’ , ‘wptexturize’ );

remove_filter( ‘comment_text’ , ‘wptexturize’ );

remove_filter( ‘list_cats’ , ‘wptexturize’ );

wptexturize

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top