2014-10-12 4 views
0

나는 사용자에게 알림 이메일을 보내는 Wordpress 플러그인을 사용하고 있습니다. 그러한 전자 메일 내에서 특정 변수를 쿼리 매개 변수로 전달하는 ahref 링크를 포함하고 싶습니다.링크에 변수를 쿼리로 올바르게 추가하는 방법은 무엇입니까?

현재 내 플러그인에서 두 개의 변수를 사용 : 나는 양식 사용자에 액세스 할 수 있도록

$email (the email address of the user) 
$scheduler->post (the name of the post, from which a user has activated the notification plugin) 

내가 지금 지시되고, URL에 두 변수를 추가 AHREF 링크를 만들려면 링크를 클릭 할 때까지

www.website.com/[email protected]&postname=example 

가 어떻게 이것을 달성 할 수

목적은이 같은 URL을 생성하는 것입니다? URL은 어떻게 보이게해야합니까?

좋아요?

<a href="http://www.example.com/?email=$email&postname=$scheduler->post">Visit this link</a> 

도움 주셔서 감사합니다.

알렉산더

답변

0

URL에 추가하기 전에 변수를 이스케이프 처리해야합니다.

$email = '[email protected]'; 
$postname = 'postname'; 
$url = 'http://www.example.com/'; 

$queryString = http_build_query(array(
    'email' => $email, 
    'postname' => $postname 
)); 

$link = '<a href="' . $url . . '?' . $queryString . '">Visit this link</a>'; 

가 대신 http_build_query()으로 사용할 수 PHP의 urlencode() 기능을 참조하십시오 PHP는 배열, 사용 예제에서 변수를 사용하여 쿼리 문자열을 구축 할 http_build_query() 기능을 포함하고 있습니다.

+0

'urlencode()'이 (가) 트릭을했습니다. 고맙습니다! – Alex

관련 문제