douzhuo2722 2013-02-05 17:18
浏览 55

在变量中包含文件

Thank you all for your help ; I found many responses to my questions on this forum but still stuck on this one . Let me explain: I have files called “participant_pledge.php” , “parents_pledge.php” …. That contain text only. The reason for it is that this text is needed in many files within my website; so I simply use “include” wherever I need it. My problem is that I also need to include those file in the content of some “email function.” That’s where I can’t find solution to include those file since it isn’t possible to use a function within a variable. The idea would be to be able to do the following:

function update ($user_id, $update_camper_data) {
...
$message='
 ...
<tr>
<td>
Participant\'s Name*:
</td>
<td>
'.$update_camper_data['participant_first_name'].'  '.$update_camper_data['participant_middle_initial'].'  '.$update_camper_data['participant_last_name'].'
</td>

include ‘participant_pledge.php;  //which does not work inside a variable

...';
mail($to, $subject, $message, $headers);
}

I have considered constant variables but could not make it work (but maybe I used it the wrong way)… Anyways, thank you in advance for your time and help on this question.

Mike.

  • 写回答

2条回答 默认 最新

  • dongsui4658 2013-02-05 17:21
    关注

    It is in fact possible in a way to use a 'function within a variable'. See: http://www.php.net/manual/en/functions.anonymous.php. The pattern you are describing is basically that ofa 'View Helper'. Maybe look at some frameworks and how they implement this. For example: http://framework.zend.com/manual/1.12/en/zend.view.helpers.html

    评论

报告相同问题?

悬赏问题

  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教