如何消除字符串php中的html重复项

时间:2015-08-18 04:33:05

标签: php html

我们有升级矩阵,当案件未在特定时间关闭时,我们会升级到更高级别的当局。我们发送的电子邮件应该采用特殊格式,以后我们可以更改格式,这意味着我们正在使用电子邮件模板。无论何时案例未关闭我们将获取案例详细信息,并根据定义的电子邮件模板,我们将通过php邮件代码向上级发送邮件。 在完成while循环的所有情况下,我得到的一些电子邮件内容相同 我的结果是什么

$body1='<p>Hi All,</p> <p>Please find the Escalation report  </p> <table style="height:40px;width:100px;" border="1" cellspacing="1" cellpadding="10" align="left"><caption>Escalation Report</caption> <tbody><tr><td>Contact Name</td> <td> Query Topic</td> </tr><tr><td>Maneesh Kotha</td> <td>External</td> </tr></tbody></table><p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p>Thanks and Regards,</p> <p>RF Team.</p> <p>Hi All,</p> <p>Please find the Escalation report  </p> <table style="height:40px;width:100px;" border="1" cellspacing="1" cellpadding="10" align="left"><caption>Escalation Report</caption> <tbody><tr><td>Contact Name</td> <td> Query Topic</td> </tr><tr><td>Sravani Tedla</td> <td>External</td> </tr></tbody></table><p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p>Thanks and Regards,</p> <p>RF Team.</p>';

我想要修改上面的文字,如下所示

$body1='<p>Hi All,</p> <p>Please find the Escalation report  </p> <table style="height:40px;width:100px;" border="1" cellspacing="1" cellpadding="10" align="left"><caption>Escalation Report</caption> <tbody><tr><td>Contact Name</td> <td> Query Topic</td> </tr><tr><td>Maneesh Kotha</td> <td>External</td> </tr><tr><td>Sravani Tedla</td> <td>External</td> </tr></tbody></table><p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p>Thanks and Regards,</p> <p>RF Team.</p>';

我的整个代码是`?php

if(!defined('sugarEntry')) define('sugarEntry', true);
require_once('include/entryPoint.php');
global $db;
date_default_timezone_set('UTC');
$date_sms_email= date('Y-m-d H:i:s');
$query_dateentered="select date_entered,id,state_c from cases inner join cases_cstm on cases.id=cases_cstm.id_c where deleted='0' and status='New' and date_of_answer_of_query_c='2015-08-17'";
$result_dateentered=$db->query($query_dateentered);
while($row_dateentered=$db->fetchByAssoc($result_dateentered)){
    $state=$row_dateentered['state_c'];
    $case_id=$row_dateentered['id'];
    $datecreated=$row_dateentered['date_entered'];
    $today_date= date('Y-m-d H:i:s');
    $diff = abs( strtotime($datecreated) - strtotime($today_date));
    $days=intval( $diff / 86400 );
    $hours=intval( ( $diff % 86400 ) / 3600);
    $query_details_level1="SELECT emailtemplate_id_c,sms_text_level1_c,email1_level1_c,email2_level1_c,email3_level1_c,phone_number1_level1_c,phone_number2_level1_c,phone_number3_level1_c FROM bhea_escalation_matrix INNER JOIN bhea_escalation_matrix_cstm ON bhea_escalation_matrix.id=bhea_escalation_matrix_cstm.id_c WHERE state_c='$state' AND deleted='0'";
        $result_details_level1=$db->query($query_details_level1);
        $row_details_level1=$db->fetchByAssoc($result_details_level1);
        $emailtemplateid=$row_details_level1['emailtemplate_id_c'];
        $emailtemplate_query="SELECT body_html,subject FROM email_templates WHERE id='$emailtemplateid'";
        $emailtemplate_result=$db->query($emailtemplate_query);
        $emailtemplate_row=$db->fetchByAssoc($emailtemplate_result);
        $body=$emailtemplate_row['body_html'];
        $subject=$emailtemplate_row['subject'];
        $email1=$row_details_level1['email1_level1_c'];
        $email2=$row_details_level1['email2_level1_c'];
        $email3=$row_details_level1['email3_level1_c'];
        $smstext=$row_details_level1['sms_text_level1_c'];
        $phone1=$row_details_level1['phone_number1_level1_c'];
        $phone2=$row_details_level1['phone_number2_level1_c'];
        $phone3=$row_details_level1['phone_number3_level1_c'];
        $needle = '$acase_';
        $matches = array_filter(str_word_count($body,1,'_$'),
                    function($item) use ($needle) {
                        return (levenshtein($item,$needle,1,1,0) == 0);
                    }
                   );
         // echo "Hai"; 
         foreach ($matches as $values) {
            $correctvariables=$values;
            $queryvariables=str_replace('$acase_',"",$correctvariables);

            $query_casevariables="SELECT $queryvariables FROM cases inner join cases_cstm on cases.id=cases_cstm.id_c where id='$case_id'";
            $result_casevariables=$db->query($query_casevariables);
            $row_casevariables=$db->fetchByAssoc($result_casevariables);
            $result_case=$row_casevariables[$queryvariables];
            $body= str_replace(array($correctvariables),array($result_case),$body);
        }

        $body1.=$body;
        }
        echo $body1;
        ?>

` 提前致谢

1 个答案:

答案 0 :(得分:0)

<?php

$body='<p>Hi All,</p> <p>Please find the Escalation report  </p> <table style="height:40px;width:100px;" border="1" cellspacing="1" cellpadding="10" align="left"><caption>Escalation Report</caption> <tbody><tr><td>Contact Name</td> <td> Query Topic</td> </tr><tr><td>Maneesh Kotha</td> <td>External</td> </tr></tbody></table><p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p>Thanks and Regards,</p> <p>RF Team.</p> <p>Hi All,</p> <p>Please find the Escalation report  </p> <table style="height:40px;width:100px;" border="1" cellspacing="1" cellpadding="10" align="left"><caption>Escalation Report</caption> <tbody><tr><td>Contact Name</td> <td> Query Topic</td> </tr><tr><td>Sravani Tedla</td> <td>External</td> </tr></tbody></table><p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p>Thanks and Regards,</p> <p>RF Team.</p>';

$temp=substr($body,0,strpos($body,"<table"));

?>

使用此代码$ temp将包含您上面提到的有趣的内容