이메일 시스템에서 사용할 템플릿을 작업 중입니다. 그리고 고객에게 메일을 보낼 것입니다.
이것은 내 create-email.php 파일이 될 것입니다.
그리고 textarea를 갖게 될 것입니다. 사용할 변수가 필요합니다.
안녕하세요, {firstname} {lastname} ,
귀하의 이메일 주소 {email} 이 뉴스 레터 목록에 추가되었습니다.
다음 링크를 사용하여 구독을 취소 할 수 있습니다. http://example.com/unsubscribe.php?memberid= {memberid} & email = {email }
이 텍스트 영역은 send-email.php에 POST됩니다.
내 문제는 여기서 시작됩니다. 나는 대체 할 {FIRSTNAME} {LASTNAME} {이메일} {MEMBERID을} 내 데이터가 내 데이터베이스에서 나오는의와 함께.
어떻게 할 수 있습니까?
값 배열과 함께 str_replace를 사용하십시오.
// $array can be set from a query perhaps?
$array = array('firstname' => 'Bob', 'lastname' => 'Dave',...);
// $template could also be a string which is a large block such as yours above.
$template = file_get_contents($template);
foreach($array as $key => $value) {
$template = str_replace("{$key}", $value, $template);
}
두 개의 배열을 사용하여이 작업을 수행 할 수도 있지만 실제로 더 많은 메모리를 사용한다고 주장하지는 않으며 어떤 필드가 어떤 값과 일치하는지 추적 할 때 문제가됩니다.
// Array of fields to replace
$fields = array('firstname', 'lastname',...);
$values = array('bob', 'dave',...);
$template = file_get_contents($template);
$template = str_replace($fields, $values, $template);
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다