Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 错误:未终止的字符串文字_Php_Javascript_Jquery_Zend Form - Fatal编程技术网

Php 错误:未终止的字符串文字

Php 错误:未终止的字符串文字,php,javascript,jquery,zend-form,Php,Javascript,Jquery,Zend Form,我有一些HTML数据是从Zend_Form生成的 我想将其附加到div#wrapper元素,但我的尝试引发了一个错误:未终止的字符串文本 我该怎么做才能修好它 注意:好的,每个人看起来都像假设我忘记在代码上添加php标记,但事实并非如此。这是我的“真实”代码 <?php class Admin_Elements_Dialog { private $_name; private $_title; private $_action; private $_button = null; priv

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

我想将其附加到
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>');
});
但肯定有更好的方法。这样的话,你就必须注意可转义字符和换行符


还有,我忍不住说:“提前谢谢”;没有尾随的“d”。

您在Javascript中使用的是PHP连接运算符

Javascript的连接运算符是
+

$(document).ready(function() {
     $("div#wrapper").append('<div id="dialog" title="Add new blog">' + <?php echo $this->form->render() ?> + '</div>');
});
但肯定有更好的方法。这样的话,你就必须注意可转义字符和换行符


还有,我忍不住说:“提前谢谢”;没有尾随的“d”。

您混合了PHP和JavaScript代码。您始终需要记住,PHP在服务器上运行,Javascript在客户机上运行

您想要的可能是:

$(document).ready(function() {
     $("div#wrapper").append('<div id="dialog" title="Add new blog"><?php echo $this->form->render(); ?></div>');
});
$(文档).ready(函数(){
$(“div#wrapper”)。附加(“”);
});

显然,您需要确保该字符串中的所有换行符和单引号都被转义(
\n
\'

您正在混合使用PHP和JavaScript代码。您始终需要记住,PHP在服务器上运行,Javascript在客户机上运行

您想要的可能是:

$(document).ready(function() {
     $("div#wrapper").append('<div id="dialog" title="Add new blog"><?php echo $this->form->render(); ?></div>');
});
$(文档).ready(函数(){
$(“div#wrapper”)。附加(“”);
});

显然,您需要确保该字符串中的所有换行符和单引号都被转义(
\n
\'

混合使用javascript和PHP代码

我认为,如果您的js是由PHP脚本生成的,这可能会更好:

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

混合使用javascript和PHP代码

我认为,如果您的js是由PHP脚本生成的,这可能会更好:

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

在客户端运行Javascript之前,在服务器端解析PHP。因此,PHP将直接注入Javascript字符串中。然后JQuery将把它附加到指定的位置

$(document).ready(function() {
     $("div#wrapper").append('<div id="dialog" title="Add new blog"><?php echo $this->form->render() ?></div>');
});
$(文档).ready(函数(){
$(“div#wrapper”)。附加(“”);
});

在客户端运行Javascript之前,在服务器端解析PHP。因此,PHP将直接注入Javascript字符串中。然后JQuery将把它附加到指定的位置

$(document).ready(function() {
     $("div#wrapper").append('<div id="dialog" title="Add new blog"><?php echo $this->form->render() ?></div>');
});
$(文档).ready(函数(){
$(“div#wrapper”)。附加(“”);
});

基本上,当您的PHP代码呈现在服务器上时,它会解析介于
之间的所有内容。因此,当您的代码呈现时,它会得到如下结果

$(document).ready(function() {
    $("div#wrapper").append('<div id="dialog" title="Add new blog">' + <form></form> + '</div>');
});
$(文档).ready(函数(){
$(“div#wrapper”).append(“”+“”);
});
请注意,生成的JS代码有一个
元素,该元素没有用引号括起来。这将导致“未终止字符串文字”错误

要解决这个问题,你只需要用引号括起来,比如

$("div#wrapper").append(
    '<div id="dialog" title="Add new blog">' + '<?php $this->form->render(); ?>' + '</div>'
)
$(“div#wrapper”).append(
'' + '' + ''
)
或者,您可以将PHP插入JS字符串:

$("div#wrapper").append(
    '<div id="dialog" title="Add new blog"><?php $this->form->render(); ?></div>'
)
$(“div#wrapper”).append(
''
)

基本上,当您的PHP代码呈现在服务器上时,它会解析介于
之间的所有内容。因此,当您的代码呈现时,它会得到如下结果

$(document).ready(function() {
    $("div#wrapper").append('<div id="dialog" title="Add new blog">' + <form></form> + '</div>');
});
$(文档).ready(函数(){
$(“div#wrapper”).append(“”+“”);
});
请注意,生成的JS代码有一个
元素,该元素没有用引号括起来。这将导致“未终止字符串文字”错误

要解决这个问题,你只需要用引号括起来,比如

$("div#wrapper").append(
    '<div id="dialog" title="Add new blog">' + '<?php $this->form->render(); ?>' + '</div>'
)
$(“div#wrapper”).append(
'' + '' + ''
)
或者,您可以将PHP插入JS字符串:

$("div#wrapper").append(
    '<div id="dialog" title="Add new blog"><?php $this->form->render(); ?></div>'
)
$(“div#wrapper”).append(
''
)

好的,我用preg\u replace函数删除了所有新行和分页符,解决了我的问题

preg_replace('/[\r\n]+/', null, $this->_content)

好的,我用preg_replace函数删除了所有新行和分页符,解决了我的问题

preg_replace('/[\r\n]+/', null, $this->_content)


这仍然行不通。您需要将
包装在
$this->form->render()
周围,因为这是PHP代码。另一个选项是在PHP中将整个JQuery脚本括在引号中和
echo
。@ThiefMaster@Brice:复制/粘贴明显失败。错别字修正了。好的,不止这些。布莱恩:你把它放好了,我把它拿走了。事后看来,它可能确实属于这个问题。这仍然行不通。您需要将
包装在
$this->form->render()
周围,因为这是PHP代码。另一个选项是在PHP中将整个JQuery脚本括在引号中和
echo
。@ThiefMaster@Brice:复制/粘贴明显失败。错别字修正了。好的,不止这些。布莱恩:你把它放好了,我把它拿走了。事后看来,这可能确实属于这个问题。他把PHP和Javascript混合在一起,事实也是如此。@Tomalak:很抱歉我的英语不好,尽管我对弦乐乐器很敏感,如果你解决了问题,请将解决方案作为答案发布,而不是编辑。是的,我必须等5个小时才能完成:-)他把PHP和Javascript混合在一起,确实如此。@Tomalak:很抱歉我的英语不好,尽管我对弦乐器很敏感,如果你解决了问题,请将解决方案作为答案发布,而不是编辑。是的,我必须等待接下来的5个小时才能完成:-)您忘记了在呈现表单后进行回音:我不知道呈现是否返回字符串或显示内容。您忘记了在呈现表单后进行回音:我不知道呈现是否返回字符串或显示内容。显然,脚本是在函数renderscript上的PHP类中生成的只是其中的一小部分。显然,脚本是在函数renderscript上的PHP类中生成的