English 中文(简体)
使用 PPST 变量的文本内容制作 PHP 格式信函和 PHP 格式信函
原标题:Making a form letter with PHP with text content from a variable from the POST

我正试图用 PHP 做一个表格信。 我有一个视图, 它有一个文本区域, 含有一些预设的文本。 文本就像一封信: 亲爱的索索等, 等等 。

我有一些地方需要填入 db 中的具体动态数据, 但除此之外我还需要让用户根据需要修改电子邮件其他部分的措辞。 我正在考虑设置一个随机字符序列来标记我将要插入的新值的每个位置 。

因此,我将表格提交到 PHP 页面,然后将文本拖到字符串变量中。 当我准备用电子邮件发送时,我需要确保这些占位符更新。 我如何才能用变量的值替换字符串变量的内容?

EDIT - 示例。 这是我目前在 PHP 文件的字符串变量中找到的, 它正在处理窗体的动作 。

嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨,嗨。

我希望你做的很好 我想提醒你 几天后你需要做点什么

作为一个团队,我们目前的比例是百分之百。

最佳回答

我过去要做的是做如下一些事情。

$email_text = "Hello ###user###,    
                  You have a new Event on ###date### at ###time### for ###hours### hour.    
                  Please let me know if you are attending. 

                  Have Fun.
                  ###site###";

$email_text =   str_replace( ###user### ,$username,$email_text);
$email_text =   str_replace( ###date### ,date( M dS, Y , strtotime($date)),$email_text);
$email_text =   str_replace( ###time### ,$time,$email_text);
$email_text =   str_replace( ###hours### ,$hours,$email_text);
$email_text =   str_replace( ###site### ,$site,$email_text);

我希望这将非常清楚地说明,你如何解决这个问题。

问题回答

假设信件文字是这样的:

亲爱的% name%! 我来自% 城市% 。让我们去 %destation%

您的代码应该是这样的:

$letter_text = $_POST["letter_text"];
foreach(array("name", "city", "destination") as $var) {
  $letter_text = str_replace("%".$var."%", $_POST[$var], $letter_text);
}

我用了好几次,希望这能解决你要找的东西

<?php

$content = "Hi #user, 
Thanks for registering. Your username is #username.
"

$trans = array("#user" => "ABC", "#username"=> "XYZ");

echo strtr($content, $trans);

?>

我认为您可以很容易地使用此选项。 只要将内容变量更改为您所在的字符串, 将占位符( 从 # 开始) 更改为占位符。 为这些占位符在数据库或$_POST 中设定 $trans 数组中的值, 无论您需要什么 。





相关问题
Parse players currently in lobby

I m attempting to write a bash script to parse out the following log file and give me a list of CURRENT players in the room (so ignoring players that left, but including players that may have rejoined)...

How to get instance from string in C#?

Is it possible to get the property of a class from string and then set a value? Example: string s = "label1.text"; string value = "new value"; label1.text = value; <--and some code that makes ...

XML DOM parsing br tag

I need to parse a xml string to obtain the xml DOM, the problem I m facing is with the self closing html tag like <br /> giving me the error of Tag mismatch expected </br>. I m aware this ...

Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

Locating specific string and capturing data following it

I built a site a long time ago and now I want to place the data into a database without copying and pasting the 400+ pages that it has grown to so that I can make the site database driven. My site ...

热门标签