我无法弄清楚 ?> <? 此代码中正在执行语法。我已经搜索了 php 语法页面,这不是一个开始或结束标记,也不是一个简短的打开标记。没有它,代码将无法编译,并且我在后面的大括号中得到了一种奇怪的颜色。

if(isset($_POST)){?>
            <form method="POST" action="Form_Index.php">
   ,php,syntax"/>
	














首页 > 解决方案 > 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 应用程序作为包装器。这样,可以消除错误。此解决方法的流程如下。

  1. 从 Javascript 请求 Web 应用程序。
  2. 在 Web 应用程序中,数据是从"https://docs.google.com/spreadsheets/d/"+id+"/export?format=tsv".
  3. 从 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 应用程序。

  1. 在脚本编辑器上,通过“发布”->“部署为 Web 应用程序”打开一个对话框。
  2. “将应用程序执行为:”选择“我” 。
    • 这样,脚本作为所有者运行。
  3. “谁有权访问应用程序:”选择“任何人,甚至匿名” 。
    • 在这种情况下,不需要请求访问令牌。我认为我为您的目标推荐此设置。
    • 当然,您也可以使用访问令牌。届时,请将此设置为“任何人”。并请包括访问令牌的范围https://www.googleapis.com/auth/drive.readonly和范围。https://www.googleapis.com/auth/drive这些范围是访问 Web 应用程序所必需的。
  4. 单击“部署”按钮作为新的“项目版本”。
  5. 自动打开“需要授权”对话框。
    1. 单击“查看权限”。
    2. 选择自己的帐户。
    3. 在“此应用未验证”中单击“高级”。
    4. 点击“转到###项目名称###(不安全)”
    5. 单击“允许”按钮。
  6. 单击“确定”。
  7. 复制 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 格式的数据。

参考:

标签: phpsyntax

解决方案


您的 PHP 代码介于<?php?>

所以这?>意味着 PHP 停在那里,而 HTML 开始了。

<?只是 的简写<?php

为了增加混乱,?>关闭标签在文件末尾是可选的。


推荐阅读