简体   繁体   English

如何将查询发送到PHP页面并获取PHP中的HTML数据?

[英]How to send query to a php page and get html data in php?

I am trying to send a html email from a php class in which the data is determined by the data sent to the class's method. 我正在尝试从php类发送一封html电子邮件,其中数据由发送到类的方法的数据确定。

for example. 例如。

public function send_warning_email($user_id, $email){
   global $mail;
   $body = file_get_contents('email_processor.php');
   /// ohter codes  
}

In above example. 在上面的例子中。 I want to send query to the email_processor.php page and get the return plain text and assign it to the $body variable. 我想将查询发送到email_processor.php页面并获取返回纯文本并将其分配给$ body变量。

Is there another function I can use instead of file_get_contents() that will allow me to send query to the php page and get return text or another approach to performing this task?. 是否有我可以使用的另一个函数而不是file_get_contents(),它将允许我向php页面发送查询并获得返回文本或执行此任务的其他方法?

You can require your email_processor.php: 您可以要求使用email_processor.php:

$body = require 'email_processor.php';

In this case you must return some body in your email_processor.php 在这种情况下,您必须在email_processor.php return一些正文

Another case: you can use output buffer: 另一种情况:你可以使用输出缓冲区:

ob_start();
require 'email_processor.php';
$body = ob_get_clean();

In this case you must echo some body in your email_processor.php 在这种情况下,您必须在email_processor.php回显一些正文

Use CURL 使用CURL

$ch = curl_init();  
curl_setopt($ch, CURLOPT_URL,'email_processor.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data);     
// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);

某些操作系统只会在你传递它时读取它:

$body = file_get_contents('./email_processor.php');

如何从 html 获取和发送值<textarea>&lt;i&gt;to a PHP page?&lt;/div&gt;&lt;/i&gt;&lt;b&gt;到 PHP 页面?&lt;/div&gt;&lt;/b&gt;</textarea><div id="text_translate"><p> 我创建了一个用于图像上传的表单。 此表单还包括一个标签,用于添加有关正在上传的图像的信息。 每当单击“上传”按钮时,我都需要将标签中的文本发送到页面“savetofile.php”。</p><p> 目前图片上传正常,图片信息发送正确,但我无法从“savetofile.php”页面的标签中获取文本。</p><p> 形式</p><pre>&lt;form action="savetofile.php" enctype="multipart/form-data" id="form1" method="post"&gt; &lt;div&gt; &lt;label for="fileToUpload"&gt;Take or select photo(s)&lt;/label&gt;&lt;br/&gt; &lt;input accept="image/*" capture id="fileToUpload" name="fileToUpload" onchange="fileSelected();" type="file"/&gt; &lt;/div&gt; &lt;div&gt; &lt;br&gt;&lt;br&gt; &lt;label for="notes"&gt;Notes:&lt;/label&gt; &lt;textarea cols="50" id="notes" maxlength="2000" name="notes" placeholder="Please enter any additional information here" rows="4" onchange="this.form.submit()"&gt;&lt;/textarea&gt; &lt;br&gt;&lt;br&gt; &lt;/div&gt; &lt;div id="details"&gt;&lt;/div&gt; &lt;div&gt; &lt;input onclick="uploadFile()" type="button" value="Upload"/&gt; &lt;/div&gt; &lt;div id="progress"&gt;&lt;/div&gt; &lt;/form&gt;</pre><p> 保存到文件.php</p><pre> $text = $_POST['notes']; _log('text: '.$text);</pre><p> 上传文件()</p><pre> function uploadFile() { var fd = new FormData(); var count = document.getElementById('fileToUpload').files.length; for (var index = 0; index &lt; count; index++) { var file = document.getElementById('fileToUpload').files[index]; fd.append('myFile', file); } var xhr = new XMLHttpRequest(); xhr.upload.addEventListener("progress", uploadProgress, false); xhr.addEventListener("load", uploadComplete, false); xhr.addEventListener("error", uploadFailed, false); xhr.addEventListener("abort", uploadCanceled, false); xhr.open("POST", "savetofile.php"); xhr.send(fd); }</pre><p> 当前 output:</p><pre> Undefined index: notes... text:</pre></div> - How to get and send values from html <textarea> to a PHP page?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将html数据发送到另一个php页面 - how to send html data to another php page 发送PHP数据到HTML页面 - Send php data to html page 如何从 html 获取和发送值<textarea>&lt;i&gt;to a PHP page?&lt;/div&gt;&lt;/i&gt;&lt;b&gt;到 PHP 页面?&lt;/div&gt;&lt;/b&gt;</textarea><div id="text_translate"><p> 我创建了一个用于图像上传的表单。 此表单还包括一个标签,用于添加有关正在上传的图像的信息。 每当单击“上传”按钮时,我都需要将标签中的文本发送到页面“savetofile.php”。</p><p> 目前图片上传正常,图片信息发送正确,但我无法从“savetofile.php”页面的标签中获取文本。</p><p> 形式</p><pre>&lt;form action="savetofile.php" enctype="multipart/form-data" id="form1" method="post"&gt; &lt;div&gt; &lt;label for="fileToUpload"&gt;Take or select photo(s)&lt;/label&gt;&lt;br/&gt; &lt;input accept="image/*" capture id="fileToUpload" name="fileToUpload" onchange="fileSelected();" type="file"/&gt; &lt;/div&gt; &lt;div&gt; &lt;br&gt;&lt;br&gt; &lt;label for="notes"&gt;Notes:&lt;/label&gt; &lt;textarea cols="50" id="notes" maxlength="2000" name="notes" placeholder="Please enter any additional information here" rows="4" onchange="this.form.submit()"&gt;&lt;/textarea&gt; &lt;br&gt;&lt;br&gt; &lt;/div&gt; &lt;div id="details"&gt;&lt;/div&gt; &lt;div&gt; &lt;input onclick="uploadFile()" type="button" value="Upload"/&gt; &lt;/div&gt; &lt;div id="progress"&gt;&lt;/div&gt; &lt;/form&gt;</pre><p> 保存到文件.php</p><pre> $text = $_POST['notes']; _log('text: '.$text);</pre><p> 上传文件()</p><pre> function uploadFile() { var fd = new FormData(); var count = document.getElementById('fileToUpload').files.length; for (var index = 0; index &lt; count; index++) { var file = document.getElementById('fileToUpload').files[index]; fd.append('myFile', file); } var xhr = new XMLHttpRequest(); xhr.upload.addEventListener("progress", uploadProgress, false); xhr.addEventListener("load", uploadComplete, false); xhr.addEventListener("error", uploadFailed, false); xhr.addEventListener("abort", uploadCanceled, false); xhr.open("POST", "savetofile.php"); xhr.send(fd); }</pre><p> 当前 output:</p><pre> Undefined index: notes... text:</pre></div> - How to get and send values from html <textarea> to a PHP page? 无法将数据从html页面发送到php - Unable to send data from html page to php 如何将html表单数据导入PHP以发送电子邮件 - How to get html form data into PHP to send an email HTML get方法不会将数据发送到PHP - HTML get method wont send data to PHP 将获取数据再次发送到PHP中的另一页 - Send get data again to another page in php 如何将数据从html5表单发送到php页面进行处理,而不必重新加载页面或转到php页面 - How to send data from a html5 form to php page to process without having to reload the page or to go to the php page 如何发送和获取php变量到下一页? - How to send and get php variable to the next page? 通过PHP将SQL查询数据转换为HTML - Get SQL Query Data into HTML via PHP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM