2011-11-30 4 views
0

나는 여기에서하려고하는 2 가지를 가지고있다. 그러나 나는 비참하게 실패하고 있으며 모든 것을 시도했기 때문에 그 이유를 모른다.PHP str_replace issues

  1. 본인이 저작권을 제거 str_replace을 사용하려고하지만 이메일의 저작권 서명이 나타나고있다.

  2. 몇 가지 이유로 메시지의 임의의 부분에 번호가 입력됩니다. 나는 이것이 왜 일어나고 있는지 정말로 혼란 스럽다. 아래는 PHP 코드와 HTML 출력의 모습입니다.

**** NEW 출력 : **** 나는 qprint을 추가하고 지금은 얻을 : enter image description here

출력 : Example

코드 :

<?php 

/* connect to gmail */ 
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX'; 
$username = '[email protected]'; 
$password = 'Password'; 

/* try to connect */ 
$inbox = imap_open($hostname, $username, $password) or die('Cannot connect to Gmail: ' . imap_last_error()); 

/* grab emails */ 
$emails = imap_search($inbox, 'ALL'); 

/* if emails are returned, cycle through each... */ 
if ($emails) { 

    /* begin output var */ 
    $output = ''; 

    /* put the newest emails on top */ 
    rsort($emails); 

    /* for every email... */ 
    foreach ($emails as $email_number) { 

     /* get information specific to this email */ 
     $overview = imap_fetch_overview($inbox, $email_number, 0); 
     $message = imap_fetchbody($inbox, $email_number, 2); 
     $DateFormatted = str_replace("-0500", "", $overview[0] -> date); 

     /* output the email header information */ 
     $output .= '<span class="msg_subject">' . $overview[0] -> subject . '</span> | '; 
     $output .= '<span class="msg_date"> ' . $DateFormatted . '</span><br />'; 

     $bodyFormatted = str_replace("This e-mail (and attachment(s)) is confidential, proprietary, may be subject to copyright and legal privilege and no related rights are waived. If you are not the intended recipient or its agent, any review, dissemination, distribution or copying of this e-mail or any of its content is strictly prohibited and may be unlawful. All messages may be monitored as permitted by applicable law and regulations and our policies to protect our business. E-mails are not secure and you are deemed to have accepted any risk if you communicate with us by e-mail. If received in error, please notify us immediately and delete the e-mail (and any attachments) from any computer or any storage medium without printing a copy. 

Ce courriel (ainsi que ses pièces jointes) est confidentiel, exclusif, et peut faire l’objet de droit d’auteur et de privilège juridique; aucun droit connexe n’est exclu. Si vous n’êtes pas le destinataire visé ou son représentant, toute étude, diffusion, transmission ou copie de ce courriel en tout ou en partie, est strictement interdite et peut être illégale. Tous les messages peuvent être surveillés, selon les lois et règlements applicables et les politiques de protection de notre entreprise. Les courriels ne sont pas sécurisés et vous êtes réputés avoir accepté tous les risques qui y sont liés si vous choisissez de communiquer avec nous par ce moyen. Si vous avez reçu ce message par erreur, veuillez nous en aviser immédiatement et supprimer ce courriel (ainsi que toutes ses pièces jointes) de tout ordinateur ou support de données sans en imprimer une copie.", "", $message); 
     /* output the email body */ 
     $output .= '<span class="msg_body">' . $bodyFormatted . '</span><br /><br />'; 

    } 

    echo $output; 
} 

/* close the connection */ 
imap_close($inbox); 
?> 
+0

'임의의 문자열이'같다 :

다음은 수정 된 코드입니다. 그들은 무작위가 아니지만''','',''및 기타 악센트 문자의 인코딩 된 버전입니다. – Qqwy

+0

악센트 부호가없는 곳에서 번호를 추가합니다. 예를 들어 – Bulvak

+0

과 같은 원래의 이메일 : Wolfedale/Montreal 데이터 센터 (SDE)는 12 월 6 일/7 일 (Wolfedale) 및 12 월 12 일/13 일에 네트워크 유지 보수가 진행됩니다. (몬트리올). 이 유지 관리 중에는 중단 시간이 발생하지 않습니다. 범위 : 영향을받는 라우터에서 발견 된 문제로 인해 응급 네트워크 유지 관리가 필요합니다. 영향 : 미디어 인프라에서 호스팅되는 모든 웹 사이트 (향후 마이그레이션 예정) : – Bulvak

답변

2

전자 메일이 어떤 형식으로 전달되는지는 알 수 없지만 imap_qprint($message);을 사용하여 올바른 형식으로 메시지를 얻은 다음 str_replace('&copy;','',$bodyFormatted);을 HTML 형식이어야하므로 보이게됩니다.

난수는 imap_qprint()를 사용하지 않은 것입니다. 메시지 내에서 변환해야하는 8 비트 문자열이 있습니다. 인코딩 된 값으로

/* get information specific to this email */ 
    $overview = imap_fetch_overview($inbox, $email_number, 0); 
    $message = imap_fetchbody($inbox, $email_number, 2); 
    $message = imap_qprint($message); 
    $DateFormatted = str_replace("-0500", "", $overview[0] -> date); 

    /* output the email header information */ 
    $output .= '<span class="msg_subject">' . $overview[0] -> subject . '</span> | '; 
    $output .= '<span class="msg_date"> ' . $DateFormatted . '</span><br />'; 

    $string = "you should get the HTML and put it in there, I'm sure there are things like &nbsp; and other html chars that it's not finding"; 
    $bodyFormatted = str_replace($string, "", $message); 
    /* output the email body */ 
    $output .= '<span class="msg_body">' . $bodyFormatted . '</span><br /><br />'; 
+0

약간 혼란 스러울 수있는 코드 조각을 편집하여 붙여 주실 수 있습니까? 사용자가 나에게 전자 메일을 보내면 서명 코드에 저작권 서명 등이 포함되어 HTML에 표시됩니다. str_replace ('©', '', $ bodyFormatted);라고 말합니다. 하지만 무엇입니까 & copy – Bulvak

+0

©은 HTML로 인코딩 된 버전의 '©'기호입니다. 나는 이것이 당신의 HTML 문제를 어떻게 수정하는지 보지 못했다. – Qqwy

+0

전체 복사본 오른쪽 단락을 제거하고 싶습니다. 내가 HTML을 에코 할 때 표시하고 싶지 않습니다. 내 코드에서 편집해야하는 것은 무엇입니까? – Bulvak