wdc63
V2EX  ›  PHP

请教 PHP 问题, PHP 读取 html 文件为变量,将其赋值给 js 总是失败

  •  
  •   wdc63 · Oct 10, 2017 · 3509 views
    This topic created in 3320 days ago, the information mentioned may be changed or developed.

    我是完全不会 PHP,为了解决一个读取 html 文件到可视化编辑器中的问题,在网上搜索,自己尝试了几个小时都没找到有效的办法,因此求助

    http://gist.github.com/wdc63/358cab5f0d1905c43a28c0aa7d9aa5a0

    以上运行总是失败,无法 alert 任何东西 html 文件示例: http://123.206.114.168:15679/test.html

    10 replies  •  2017-10-10 20:21:19 +08:00
    cxbig
    cxbig
    Oct 10, 2017 via iPad
    1
    先把变量用 var_dump 出来看看
    另外直接输出 html 文本显然会有大量的单双引号,这会破坏 Javascrip 结构
    smallyin
    smallyin
    Oct 10, 2017
    2
    两个问题:
    1 ) php 文件第 4 行中括号是多余的
    2 ) var gethtml = "<?php echo $htmlData ;?>"; 改成 var gethtml = `<?php echo $htmlData ;?>`;
    cxbig
    cxbig
    Oct 10, 2017 via iPad
    3
    更正:Javascript。手残,漏了个字母。
    wdc63
    wdc63
    OP
    Oct 10, 2017
    4
    @smallyin 谢谢,我先试试
    wdc63
    wdc63
    OP
    Oct 10, 2017
    5
    @cxbig
    @smallyin
    没有 php 编程环境,都是在服务器上直接改 php 文件然后远程访问看有问题没
    wdc63
    wdc63
    OP
    Oct 10, 2017
    6
    @smallyin 改之后还是不行
    cxbig
    cxbig
    Oct 10, 2017 via iPad
    7
    @wdc63 var_dump 可以在任何环境使用。你先确定远程可以执行 PHP ?
    niuoh
    niuoh
    Oct 10, 2017
    8
    php 赋值给 js 的时候 html encode
    js 使用的时候再 html decode
    smallyin
    smallyin
    Oct 10, 2017
    9
    什么浏览器?我在 chrome 下亲测可以的呀
    wdc63
    wdc63
    OP
    Oct 10, 2017
    10
    @cxbig 谢谢,解决了,确实是浏览器的问题。
    @smallyin
    @niuoh
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2538 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 11:52 · PVG 19:52 · LAX 03:52 · JFK 06:52
    ♥ Do have faith in what you're doing.