gpt4 book ai didi

php - 错误: Unterminated string literal

转载 作者:行者123 更新时间:2023-11-28 21:21:21 26 4
gpt4 key购买 nike

我有一些从 Zend_Form 生成的 HTML 数据。

我想将其附加到 div#wrapper 元素,但我的尝试引发了错误:未终止的字符串文字

我应该做什么来修复它?

注意:好吧,每个人看起来都假设我忘记在我的代码上添加 php 标签,但事实并非如此。这是我的“真实”代码

<?php

class Admin_Elements_Dialog {
private $_name;
private $_title;
private $_action;
private $_button = null;
private $_content;
private $_options = array();

public function __construct($options) {
$this->_options = $options;
}

public function setName($name) {
$this->_name = $name;

return $this;
}

public function setTitle($title) {
$this->_title = $title;

return $this;
}

public function setAction($action) {
$this->_action = $action;

return $this;
}

public function setOpener($button) {
if ($button instanceof Admin_Elements_Buttons)
$this->_button = $button;

return $this;
}

public function setContent($content) {
$this->_content = $content;

return $this;
}

public function renderScript() {
$html = array();

$html[] = '$(document).ready(function() {
$("body").append(\'<div id="' . $this->_name . '" title="' . $this->_title . '" class="ui-helper-hidden">' . $this->_content . '</div>\');

var dialog = $("#' . $this->_name . '").dialog(' . Zend_Json::encode($this->_options, false, array('enableJsonExprFinder' => true)) . ');

$("#' . $this->_button->getId() . '").click(function() {
$("#' . $this->_name . '").dialog("open");

return false;
});
});';

$html[] = '';

return join($html, PHP_EOL);
}
}
?>

最佳答案

您正在 Javascript 中使用 PHP 连接运算符 .

Javascript 的连接运算符是 +:

$(document).ready(function() {
$("div#wrapper").append('<div id="dialog" title="Add new blog">' + <?php echo $this->form->render() ?> + '</div>');
});

此外,PHP 代码会逐字插入到您的页面中。如果 $this->form->render() 没有生成字面上引号封装的字符串,则生成的 Javascript 将无效。

你可能的意思是:

$(document).ready(function() {
$("div#wrapper").append('<div id="dialog" title="Add new blog"><?php echo $this->form->render() ?></div>');
});

但肯定有更好的方法。这样,您就必须留意可转义的字符和换行符。

而且,我无法抗拒:这是“提前致谢”;没有尾随“d”。

关于php - 错误: Unterminated string literal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6293663/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com