php - PHP 语法 ?>
我无法弄清楚 ?> <? 此代码中正在执行语法。我已经搜索了 php 语法页面,这不是一个开始或结束标记,也不是一个简短的打开标记。没有它,代码将无法编译,并且我在后面的大括号中得到了一种奇怪的颜色。
if(isset($_POST)){?>
<form method="POST" action="Form_Index.php">
问题描述
我无法弄清楚 ?> <? 此代码中正在执行语法。我已经搜索了 php 语法页面,这不是一个开始或结束标记,也不是一个简短的打开标记。没有它,代码将无法编译,并且我在后面的大括号中得到了一种奇怪的颜色。
if(isset($_POST)){?>
<form method="POST" action="Form_Index.php">
User <input type="text" name="userTwo"></input><br/>
Pass <input type="password" name="passTwo"></input><br/>
<input type="submit" name="submit" value="Go"></input>
</form>
<?}
我相信你的目标如下。
- 您想使用 Javascript 从 Google 电子表格中检索 TSV 格式的数据。
- 您的电子表格已公开共享。
为此,这个答案怎么样?
问题和解决方法:
我可以从你的问题中确认同样的情况。不幸的是,我无法删除此错误。因此,在这种情况下,作为一种解决方法,我想建议使用由 Google Apps 脚本创建的 Web 应用程序作为包装器。这样,可以消除错误。此解决方法的流程如下。
- 从 Javascript 请求 Web 应用程序。
- 在 Web 应用程序中,数据是从
"https://docs.google.com/spreadsheets/d/"+id+"/export?format=tsv"
.
- 从 Web 应用返回 TSV 格式的数据。
用法:
请执行以下流程。
1. 新建 Google Apps Script 项目。
Web Apps 的示例脚本是 Google Apps 脚本。所以请创建一个 Google Apps Script 项目。
如果要直接创建,请访问https://script.new/。在这种情况下,如果您没有登录 Google,则会打开登录屏幕。所以请登录谷歌。至此,Google Apps Script 的脚本编辑器被打开。
2. 准备脚本。
请将以下脚本(Google Apps 脚本)复制并粘贴到脚本编辑器中。此脚本适用于 Web 应用程序。
function doGet() {
let id = "1zD3eIL8LCTJ8F_8U3kWA6k5WPJNKr_UZ_93bnARlMxQ"; // This is from your script.
let str = "https://docs.google.com/spreadsheets/d/"+id+"/export?format=tsv"; // This is from your script.
const value = UrlFetchApp.fetch(str);
return ContentService.createTextOutput(value.getContentText());
}
如果您的 Google 电子表格未公开共享,请进行如下修改。
function doGet() {
let id = "1zD3eIL8LCTJ8F_8U3kWA6k5WPJNKr_UZ_93bnARlMxQ"; // This is from your script.
let str = "https://docs.google.com/spreadsheets/d/"+id+"/export?format=tsv"; // This is from your script.
const value = UrlFetchApp.fetch(str, {headers: {authorization: "Bearer " + ScriptApp.getOAuthToken()}});
return ContentService.createTextOutput(value.getContentText());
// DriveApp.getFiles() // This is used for automatically detecting the scope.
}
3. 部署 Web 应用程序。
- 在脚本编辑器上,通过“发布”->“部署为 Web 应用程序”打开一个对话框。
- 为“将应用程序执行为:”选择“我” 。
- 这样,脚本作为所有者运行。
- 为“谁有权访问应用程序:”选择“任何人,甚至匿名” 。
- 在这种情况下,不需要请求访问令牌。我认为我为您的目标推荐此设置。
- 当然,您也可以使用访问令牌。届时,请将此设置为“任何人”。并请包括访问令牌的范围
https://www.googleapis.com/auth/drive.readonly
和范围。https://www.googleapis.com/auth/drive
这些范围是访问 Web 应用程序所必需的。
- 单击“部署”按钮作为新的“项目版本”。
- 自动打开“需要授权”对话框。
- 单击“查看权限”。
- 选择自己的帐户。
- 在“此应用未验证”中单击“高级”。
- 点击“转到###项目名称###(不安全)”
- 单击“允许”按钮。
- 单击“确定”。
- 复制 Web 应用程序的 URL。就像
https://script.google.com/macros/s/###/exec
。
- 当您修改 Google Apps 脚本时,请重新部署为新版本。这样,修改后的脚本就会反映到 Web 应用程序中。请注意这一点。
4. 使用 Web Apps 运行该功能。
当您使用它时,请按如下方式修改您的 Javascript 脚本并进行测试。
从:
let id="1zD3eIL8LCTJ8F_8U3kWA6k5WPJNKr_UZ_93bnARlMxQ"
let str="https://docs.google.com/spreadsheets/d/"+id+"/export?format=tsv";
至:
let str = "https://script.google.com/macros/s/###/exec";
笔记:
- 当您修改 Web Apps 的脚本时,请将 Web Apps 重新部署为新版本。这样,最新的脚本就会反映到 Web 应用程序中。请注意这一点。
- 在我的环境中,我可以确认,当使用上述解决方法时,不会发生错误,并且可以检索 TSV 格式的数据。
参考:
解决方案
您的 PHP 代码介于<?php
和?>
所以这?>
意味着 PHP 停在那里,而 HTML 开始了。
<?
只是 的简写<?php
。
为了增加混乱,?>
关闭标签在文件末尾是可选的。
推荐阅读
- azure - 如何将 .NET 核心控制台应用部署到 Azure Kubernetes 服务?
- react-native - 为什么我有一个预期的结束标签错误?
- java - 如何在不丢失纵横比的情况下将图像放入 Shape 中?
- php - php 7上的变量声明与?近型
- c# - 有没有一种好方法可以将多个相似的数据模型(具有一些独特的属性)包装到数据库中的一个表中?
- r - 使用 R,如何使用主成分创建和索引?
- python - 在 Python Pandas 中创建重复的 int 子索引
- javascript - 嵌入 YouTube Cookie 的 JS 拦截和删除
- flutter - 如何随机播放从 firebase 检索到的视频?
- python - pylint 或 flake8 的声明性 Jenkins 管道语法
我无法弄清楚 ?> <? 此代码中正在执行语法。我已经搜索了 php 语法页面,这不是一个开始或结束标记,也不是一个简短的打开标记。没有它,代码将无法编译,并且我在后面的大括号中得到了一种奇怪的颜色。
if(isset($_POST)){?>
<form method="POST" action="Form_Index.php">
问题描述
我无法弄清楚 ?> <? 此代码中正在执行语法。我已经搜索了 php 语法页面,这不是一个开始或结束标记,也不是一个简短的打开标记。没有它,代码将无法编译,并且我在后面的大括号中得到了一种奇怪的颜色。
if(isset($_POST)){?>
<form method="POST" action="Form_Index.php">
User <input type="text" name="userTwo"></input><br/>
Pass <input type="password" name="passTwo"></input><br/>
<input type="submit" name="submit" value="Go"></input>
</form>
<?}
我相信你的目标如下。
- 您想使用 Javascript 从 Google 电子表格中检索 TSV 格式的数据。
- 您的电子表格已公开共享。
为此,这个答案怎么样?
问题和解决方法:
我可以从你的问题中确认同样的情况。不幸的是,我无法删除此错误。因此,在这种情况下,作为一种解决方法,我想建议使用由 Google Apps 脚本创建的 Web 应用程序作为包装器。这样,可以消除错误。此解决方法的流程如下。
- 从 Javascript 请求 Web 应用程序。
- 在 Web 应用程序中,数据是从
"https://docs.google.com/spreadsheets/d/"+id+"/export?format=tsv"
. - 从 Web 应用返回 TSV 格式的数据。
用法:
请执行以下流程。
1. 新建 Google Apps Script 项目。
Web Apps 的示例脚本是 Google Apps 脚本。所以请创建一个 Google Apps Script 项目。
如果要直接创建,请访问https://script.new/。在这种情况下,如果您没有登录 Google,则会打开登录屏幕。所以请登录谷歌。至此,Google Apps Script 的脚本编辑器被打开。
2. 准备脚本。
请将以下脚本(Google Apps 脚本)复制并粘贴到脚本编辑器中。此脚本适用于 Web 应用程序。
function doGet() {
let id = "1zD3eIL8LCTJ8F_8U3kWA6k5WPJNKr_UZ_93bnARlMxQ"; // This is from your script.
let str = "https://docs.google.com/spreadsheets/d/"+id+"/export?format=tsv"; // This is from your script.
const value = UrlFetchApp.fetch(str);
return ContentService.createTextOutput(value.getContentText());
}
如果您的 Google 电子表格未公开共享,请进行如下修改。
function doGet() { let id = "1zD3eIL8LCTJ8F_8U3kWA6k5WPJNKr_UZ_93bnARlMxQ"; // This is from your script. let str = "https://docs.google.com/spreadsheets/d/"+id+"/export?format=tsv"; // This is from your script. const value = UrlFetchApp.fetch(str, {headers: {authorization: "Bearer " + ScriptApp.getOAuthToken()}}); return ContentService.createTextOutput(value.getContentText()); // DriveApp.getFiles() // This is used for automatically detecting the scope. }
3. 部署 Web 应用程序。
- 在脚本编辑器上,通过“发布”->“部署为 Web 应用程序”打开一个对话框。
- 为“将应用程序执行为:”选择“我” 。
- 这样,脚本作为所有者运行。
- 为“谁有权访问应用程序:”选择“任何人,甚至匿名” 。
- 在这种情况下,不需要请求访问令牌。我认为我为您的目标推荐此设置。
- 当然,您也可以使用访问令牌。届时,请将此设置为“任何人”。并请包括访问令牌的范围
https://www.googleapis.com/auth/drive.readonly
和范围。https://www.googleapis.com/auth/drive
这些范围是访问 Web 应用程序所必需的。
- 单击“部署”按钮作为新的“项目版本”。
- 自动打开“需要授权”对话框。
- 单击“查看权限”。
- 选择自己的帐户。
- 在“此应用未验证”中单击“高级”。
- 点击“转到###项目名称###(不安全)”
- 单击“允许”按钮。
- 单击“确定”。
- 复制 Web 应用程序的 URL。就像
https://script.google.com/macros/s/###/exec
。- 当您修改 Google Apps 脚本时,请重新部署为新版本。这样,修改后的脚本就会反映到 Web 应用程序中。请注意这一点。
4. 使用 Web Apps 运行该功能。
当您使用它时,请按如下方式修改您的 Javascript 脚本并进行测试。
从:let id="1zD3eIL8LCTJ8F_8U3kWA6k5WPJNKr_UZ_93bnARlMxQ"
let str="https://docs.google.com/spreadsheets/d/"+id+"/export?format=tsv";
至:
let str = "https://script.google.com/macros/s/###/exec";
笔记:
- 当您修改 Web Apps 的脚本时,请将 Web Apps 重新部署为新版本。这样,最新的脚本就会反映到 Web 应用程序中。请注意这一点。
- 在我的环境中,我可以确认,当使用上述解决方法时,不会发生错误,并且可以检索 TSV 格式的数据。
参考:
您的 PHP 代码介于<?php
和?>
所以这?>
意味着 PHP 停在那里,而 HTML 开始了。
<?
只是 的简写<?php
。
为了增加混乱,?>
关闭标签在文件末尾是可选的。