<br> 对比 <BR> str_replace 在 PHP
<br> vs. <BR> with str_replace in PHP
我正在尝试对变量 $who:
中的文本块执行 str_replace
Acme Corporation
<BR><br>Accounting Dept
<BR><br>123 Sesame St.
<BR><br>New York, NY 10021
<BR><br>(123)456-7890
我正在使用下面的 str_replace
删除 <br>
和 <BR>
标签:
$who = str_replace("<br>","%0D%0A",html_entity_decode($who));
$who = str_replace("<BR>","%0D%0A",html_entity_decode($who));
我的问题是最终结果没有去掉
标签。输出如下所示:
Acme Corporation
<BR>Accounting Dept
<BR>123 Sesame St.
<BR>New York, NY 10021
<BR>(123)456-7890
我不认为大写对于 str_replace()
来说是个问题。我也试过 pre_replace()
并且同时使用了双引号和单引号。我将其插入 mailto
link 和 html 标签的正文中。有什么建议么?先感谢您。
编辑:我试图从变量 $who 中的字符串中删除所有 br 和 BR 标签。我需要将它们替换为 %0D%0A。这是因为生成的字符串被插入到 mailto 的正文中。这是完整的代码:
//GetValues where CCDLookUps were unnecessary
$who = CCDLookUp("data", "template", "template_name = 'poscc_header'", $db);
$terms = $payment1->pterms->GetValue();
$buyer = $users->uName->GetValue();
$comp = $users->company->GetValue();
$bEmail = $users->uMail->GetValue();
$totSold = $invoices1->total->GetValue();
$tot = $invoices1->total->GetValue();
$payamt = $payment1->amount->GetValue();
$seq = $payment1->seq->GetValue();
//correct Money output
$totSold = money_format('$%i', $totSold);
$price = money_format('$%i', $price);
$tax = money_format('$%i', $tax);
$ship = money_format('$%i', $ship);
$tot = money_format('$%i', $tot);
$payamt = money_format('$%i', $payamt);
//builds header and header template
$who = str_replace("<br>","%0D%0A",html_entity_decode($who));
//$who = str_replace("<BR>",'%0D%0A',html_entity_decode($who));
$bodymsg = $who;
//main body
$bodymsg .= "%0D%0A%0D%0AConfirmation: ".$order_id."%0D%0AOrder Date: ".$odate."%0D%0ADelivery: ".$deltype;
$bodymsg .= "%0D%0ATerms: ".$terms."%0D%0ASeller ID: ".$sellerID."%0D%0ABuyer: ".$buyer."%0D%0A ".$comp;
$bodymsg .= "%0D%0A%0D%0A";
$bodymsg .= "%0D%0ATotal Items Sold: ".$totSold."%0D%0AQty: ".$qty."%0D%0AProduct: ".$prod."%0D%0APrice: ".$price;
$bodymsg .= "%0D%0ATax: ".$tax."%0D%0AShipping: ".$ship."%0D%0ATotal: ".$tot."%0D%0A%0D%0APayment Amount: ".$payamt;
$bodymsg .= "%0D%0ASeq: ".$seq."%0D%0A%0D%0A%0D%0ACustomer Copy%0D%0A%0D%0ANo Refunds/No Exchanges%0D%0A";
$bodymsg .= "Thank you";
//place into message and set to link
$mlto = "mailto:".$bEmail."&subject=Receipt%20For%20Order%23%20".$order_id."&body=".$bodymsg;
$Page->eLink->SetValue($mlto);
<?php
$result = preg_replace("~<br>~i", "\r\n", $who);
?>
i
选项让 preg_replace()
函数不区分大小写,因此它应该替换 <br>
和 <BR>
。
要在 mailto:
link 中使用它,一种可能的方法是使用 urlencode()
。
我从你的问题中了解到你想用新行替换
标记,所以你必须使用 \n 引用代码中的新行,它将如下所示
<?php
$who="Acme Corporation
<BR><br>Accounting Dept
<BR><br>123 Sesame St.
<BR><br>New York, NY 10021
<BR><br>(123)456-7890";
$who = str_replace("<br>","\n",html_entity_decode($who));
echo $who;
?>
我正在尝试对变量 $who:
中的文本块执行 str_replaceAcme Corporation
<BR><br>Accounting Dept
<BR><br>123 Sesame St.
<BR><br>New York, NY 10021
<BR><br>(123)456-7890
我正在使用下面的 str_replace
删除 <br>
和 <BR>
标签:
$who = str_replace("<br>","%0D%0A",html_entity_decode($who));
$who = str_replace("<BR>","%0D%0A",html_entity_decode($who));
我的问题是最终结果没有去掉
标签。输出如下所示:
Acme Corporation
<BR>Accounting Dept
<BR>123 Sesame St.
<BR>New York, NY 10021
<BR>(123)456-7890
我不认为大写对于 str_replace()
来说是个问题。我也试过 pre_replace()
并且同时使用了双引号和单引号。我将其插入 mailto
link 和 html 标签的正文中。有什么建议么?先感谢您。
编辑:我试图从变量 $who 中的字符串中删除所有 br 和 BR 标签。我需要将它们替换为 %0D%0A。这是因为生成的字符串被插入到 mailto 的正文中。这是完整的代码:
//GetValues where CCDLookUps were unnecessary
$who = CCDLookUp("data", "template", "template_name = 'poscc_header'", $db);
$terms = $payment1->pterms->GetValue();
$buyer = $users->uName->GetValue();
$comp = $users->company->GetValue();
$bEmail = $users->uMail->GetValue();
$totSold = $invoices1->total->GetValue();
$tot = $invoices1->total->GetValue();
$payamt = $payment1->amount->GetValue();
$seq = $payment1->seq->GetValue();
//correct Money output
$totSold = money_format('$%i', $totSold);
$price = money_format('$%i', $price);
$tax = money_format('$%i', $tax);
$ship = money_format('$%i', $ship);
$tot = money_format('$%i', $tot);
$payamt = money_format('$%i', $payamt);
//builds header and header template
$who = str_replace("<br>","%0D%0A",html_entity_decode($who));
//$who = str_replace("<BR>",'%0D%0A',html_entity_decode($who));
$bodymsg = $who;
//main body
$bodymsg .= "%0D%0A%0D%0AConfirmation: ".$order_id."%0D%0AOrder Date: ".$odate."%0D%0ADelivery: ".$deltype;
$bodymsg .= "%0D%0ATerms: ".$terms."%0D%0ASeller ID: ".$sellerID."%0D%0ABuyer: ".$buyer."%0D%0A ".$comp;
$bodymsg .= "%0D%0A%0D%0A";
$bodymsg .= "%0D%0ATotal Items Sold: ".$totSold."%0D%0AQty: ".$qty."%0D%0AProduct: ".$prod."%0D%0APrice: ".$price;
$bodymsg .= "%0D%0ATax: ".$tax."%0D%0AShipping: ".$ship."%0D%0ATotal: ".$tot."%0D%0A%0D%0APayment Amount: ".$payamt;
$bodymsg .= "%0D%0ASeq: ".$seq."%0D%0A%0D%0A%0D%0ACustomer Copy%0D%0A%0D%0ANo Refunds/No Exchanges%0D%0A";
$bodymsg .= "Thank you";
//place into message and set to link
$mlto = "mailto:".$bEmail."&subject=Receipt%20For%20Order%23%20".$order_id."&body=".$bodymsg;
$Page->eLink->SetValue($mlto);
<?php
$result = preg_replace("~<br>~i", "\r\n", $who);
?>
i
选项让 preg_replace()
函数不区分大小写,因此它应该替换 <br>
和 <BR>
。
要在 mailto:
link 中使用它,一种可能的方法是使用 urlencode()
。
我从你的问题中了解到你想用新行替换
标记,所以你必须使用 \n 引用代码中的新行,它将如下所示
<?php
$who="Acme Corporation
<BR><br>Accounting Dept
<BR><br>123 Sesame St.
<BR><br>New York, NY 10021
<BR><br>(123)456-7890";
$who = str_replace("<br>","\n",html_entity_decode($who));
echo $who;
?>