2014-01-14 55 views
0

我有一個字符串,例如「2013國際卡車 - XZ1234」,我需要urlencode()幷包含在一個mailto主題=在一個將被正確解碼的方式。我在下面的方式測試這一點:urlencode()字符串mailto:subject =帶有破折號字符,可以正確解碼

$encodedstring = urlencode("mailto:[email protected]?subject=2013 International Truck – XZ1234") 
<a href="<?php $encodedstring ?>">Email Us</a> 

然後鏈接將是這樣的:

<a href="mailto:[email protected]?subject=2013+International+Truck+%26%238211%3B+XZ1234">Email Us</a> 

然後受試者進行解碼,並在主題輸入欄顯示的是這樣的:(此在Gmail中已經過測試)

2013 International TerraStar Truck &#8211; NT2031 

是否有來urlencode替代()或其他方式對字符串進行編碼,使所有的字符,包括破折號在郵件客戶端正確解碼?

+0

這並不看起來像是用urlencode()會做自己的。你是否1000000%肯定你的代碼中沒有'htmlentities()'調用? –

+0

你是對的@Pekka웃。我沒有意識到我編碼的變量首先通過Wordpress的'the_title()' –

回答

1

您的字符串正在被雙重編碼。 %26%238211%3B&#8211;的編碼形式,它是破折號的編碼形式。跟蹤你的代碼執行,看看它被編碼了兩次。

+0

Perfect應用了'htmlentities()'。那樣做了!謝謝。我在使用'the_title()'的Wordpress中使用了一個後期標題,我需要將它改爲'html_entity_decode(get_the_title())' –

0

你可以用下面的刪除特殊格式..

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

相關問題