标签: heredoc

如何用PHP编写<<< TOC的东西?

我忘了怎么写一个看起来像这样的命令

<<TOC


bla bla

bal bal


TOC;
Run Code Online (Sandbox Code Playgroud)

它是怎么写的?

php string heredoc

0
推荐指数
1
解决办法
170
查看次数

在PHP中使用heredoc语法时遇到麻烦

<?php
        $output = <<< END 
        <table style="display: table;" class="listview rowstyle-rowhighlight" id="resourcegrid">
          <thead>
            <tr>
              <th width="70"></th>
              <th style="-moz-user-select: none;" class="sortable fd-column-0"><a class="fdTableSortTrigger" href="#">Name</a></th>
              <th style="-moz-user-select: none;" class="sortable fd-column-1"><a class="fdTableSortTrigger" href="#">Contributor</a></th>
              <th style="-moz-user-select: none;" class="sortable fd-column-3"><a class="fdTableSortTrigger" href="#">Modified</a></th>
            </tr>
          </thead><tbody>
END;

echo $output;
Run Code Online (Sandbox Code Playgroud)

当我运行它时报告:

Parse error: parse error on line 2
Run Code Online (Sandbox Code Playgroud)

但我没有看到任何异常.

php heredoc

0
推荐指数
1
解决办法
3797
查看次数

用eval(PHP)定义一堆函数

这是否接近可以接受的东西?我需要为每个HTML标记创建一个函数,并且需要将它们定义为以后在Heredoc字符串中使用.到目前为止这是我的代码.

<?php
$tags = array (h1, h2, h3, b, i);

foreach ($tags as $key => $value)
{
    eval ('function '.$value.' ($str) { return "<'.$value.'>$str</'.$value.'>"; }');
}
Run Code Online (Sandbox Code Playgroud)

这基本上处理了关于heredoc中的函数的Heredoc问题.一个简单的例子:

<<<example
<h1>This is ordinary HTML</h1>
{$h1('This is HTML via. PHP')}
example;
Run Code Online (Sandbox Code Playgroud)

我心里都做了所有的代码,所以如果它们包含任何错误,请不要惊讶.我还没有执行eval-function,但它看起来还不错.无论如何,我的问题是:这是好的,还是更好的做法:

function h1 ($str) { return ...; }
function h2 ($str) { return ...; }
function h3 ($str) { return ...; }
function b ($str) { return ...; }
function i ($str) { return ...; }
Run Code Online (Sandbox Code Playgroud)

等等 ..?

php eval function heredoc

0
推荐指数
1
解决办法
750
查看次数

heredocs语法有问题吗?

我对heredoc的语法有问题.让我先说明代码:

    function format($user_id,$user_note,$image,$dt){

        //this is the problem
      if($image=='NULL'){
     //don't display image
     }

     else {
  echo '<img src="userpics/$image" width="480" height="480">';
}
         return <<<ENDOFRETURN
       <div class ="commentbox">
                         $date
                         </div>
                             <div class="leftpanel">

                           $user_note
                        $image
                                 <div class="date">
                                    $rel
                                 </div>
                             </div>
    ENDOFRETURN;

}
Run Code Online (Sandbox Code Playgroud)

$image变量来自于数据库,它是NULL或有一个文件名.如果图像为null我不想显示<img>标签,如果它有一个值,那么我想显示它.你知道我怎么解决这个问题吗?我一直在尝试一切,但没有任何工作呢!:))

html php image heredoc

0
推荐指数
1
解决办法
429
查看次数

尝试使用heredoc在回显中打印变量时出现PHP错误

当我尝试这样做时:

var $example = "Example";
echo <<<EOT
<p>$example</p>
EOT;
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

解析错误:语法错误,意外的T_VAR .....在线...

这里发生了什么??据我所知,这应该有效.

我使用的是PHP 5.3.5.

php variables heredoc echo php-5.3

0
推荐指数
1
解决办法
353
查看次数

PHP中的heredoc出错

这段代码:

<?
echo <<<EOM 
Hello
EOM;
?>
Run Code Online (Sandbox Code Playgroud)

结果出现此错误:

解析错误:第2行的C:\ xampp\htdocs\tiketku\cari.php中的解析错误

我究竟做错了什么?

php heredoc

0
推荐指数
1
解决办法
532
查看次数

如何在PHP HEREDOC中调用数组成员?

有没有一种方法可以在PHP HEREDOC语法中调用数组成员?

我知道HEREDOC可以使用$ strings,并且行得通。我尝试调用数组成员,但是失败了:

echo <<<EOF
<tr>
<td>$inner_array_member["ID"]</td>
<td>$inner_array_member["Date"]</td>
<td>$inner_array_member["Time"]</td>
<td>$inner_array_member["Published"]</td>
<td>$inner_array_member["Article"]</td>
<td><a href="rendered.php?editarticle=$inner_array_member["ID"]">EDIT</a></td>
</tr>
EOF;
Run Code Online (Sandbox Code Playgroud)

但是,如果我将字符串重命名为简单形式($Article = $inner_array_member["Article"]),然后调用它们,一切都很好。有没有办法解决?

php string syntax heredoc

0
推荐指数
1
解决办法
557
查看次数

Bash变量始终为空

以下bash脚本的结果是输出中的"空行"

ssh dev@my_service <<EOF
  START_SERVICE_TIME_IS_UP=124
  echo $START_SERVICE_TIME_IS_UP
  exit  
EOF
Run Code Online (Sandbox Code Playgroud)

无法理解为什么.我希望在输出中看到"124".远程服务器正在运行Red Hat linux.

linux bash heredoc

0
推荐指数
1
解决办法
329
查看次数

为什么这个here-doc bash语句不会在switch case中执行

我正在为 Raspberry Pi 开发一个引导脚本。该脚本确定 Pi 本身是Model 2还是Model 3,并相应地设置其 WiFi 特性。

WiFi 特性的更改被放入/etc/rc.local文件 ( Raspbian ) 中,这是通过bootstrap.sh脚本完成的。

片段

# model revision number to determine pi
PI_MODEL=$(cat /proc/cpuinfo | grep "Revision" | awk '{print $3}')

case "$PI_MODEL" in

"rev_1A" | "rev_1B")
    # Write the wlan config to the rc.local file
    cp /etc/rc.local /etc/rc.local.backup

    (
    cat << 'EOF'
    #!/bin/sh -e

    iwconfig wlan0 mode ad-hoc essid pi-adhoc channel 6 txpower 0

    exit 0

    EOF
    ) > …
Run Code Online (Sandbox Code Playgroud)

bash heredoc switch-statement

0
推荐指数
1
解决办法
739
查看次数

为什么我的Perl脚本在EOF之前的任何地方都给出错误"找不到字符串终结符"_HTML_?

嗨,我刚刚IF在我的源中添加了一个条件,从那时起我就收到了错误

" _HTML_在EOF之前的任何地方找不到字符串终结符"

但如果我删除它,它的工作原理 IF

我是Perl和CGI的新手,我不知道如何解决这个错误.

这是我的代码:

#!"\xampp\perl\bin\perl.exe"

use CGI qw/:standard/;
use CGI::Cookie;

%cookies = CGI::Cookie->fetch;
$Cookie = $cookies{'USER'}->value;


if ($Cookie)
{

    print "Content-type: text/html\n\n";
    print<<_HTML_;

    <!DOCTYPE html>
    <!--[if lt IE 7 ]> <html lang="en" class="no-js ie6 lt8"> <![endif]-->
    <!--[if IE 7 ]>    <html lang="en" class="no-js ie7 lt8"> <![endif]-->
    <!--[if IE 8 ]>    <html lang="en" class="no-js ie8 lt8"> <![endif]-->
    <!--[if IE 9 ]>    <html lang="en" class="no-js ie9"> <![endif]-->
    <!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class="no-js"> <!--<![endif]-->
        <head> …
Run Code Online (Sandbox Code Playgroud)

perl cgi heredoc

-1
推荐指数
1
解决办法
1809
查看次数

以下PHP代码中的错误是什么?

我正在测试以下代码.我正在使用PHP heredoc,但我从Dreamweaver收到错误.如果我手动编写它,它的工作原理.如果我复制粘贴它不起作用.这是为什么?

<?php

$e=<<<EOP
whoever
EOP;

$el=<<<EOG
whatever
EOG; 
?>
Run Code Online (Sandbox Code Playgroud)

php debugging dreamweaver heredoc

-2
推荐指数
1
解决办法
115
查看次数

使用 PHP 在 HEREDOC 字符串中转义 $

我有这样的事情

$var = <<<HEREDOC
..."request": ${"hello"}...
HEREDOC;
Run Code Online (Sandbox Code Playgroud)

当然PHP认为${"hello"}是一个变量,它无法加载。

如何逃避$?

php string heredoc

-3
推荐指数
1
解决办法
122
查看次数