标签: heredoc

在PHP中使用heredoc中的变量(SQL实践)

我是PHP/SQL的新手,我试图在heredoc中使用变量,因为我需要输入大量文本.我只包括第一句话,因为它足以显示问题).

我的问题是在heredoc中,变量(见下文:$data['game_name]$data['game_owner'])不被识别为变量而是纯文本.我怎么解决这个问题?

<?php
try
{
    //i am connecting the the database base mysql 'test'
    $pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
    $bdd = new PDO('mysql:host=localhost;dbname=test', 'root', '', $pdo_options);
    //the i read the data in the databse 'video_dame'
    $response = $bdd->query('SELECT * FROM video_game');
    //pour qu'elle soit visible à l'écran, on affiche chaque entrée une à une
    while ($data= $response->fetch())
    {
    echo <<<'EX'
    <p>Game: $data['game_name]<br/>
    the owner of the game is $data['game_owner']
    </p>
    EX;
    }
    //i end the sql request
    $response->closeCursor(); …
Run Code Online (Sandbox Code Playgroud)

php sql variables heredoc

33
推荐指数
1
解决办法
4万
查看次数

我可以在Ruby中的heredoc中访问变量吗?

如果我有方法

  def some_method p = {}
    string = <<-MY_TERMINATOR
      Example text blah blah
      lorem ipsum something or another
    MY_TERMINATOR
  end
Run Code Online (Sandbox Code Playgroud)

如何从heredoc中访问变量p [:name]?

ruby string heredoc

32
推荐指数
1
解决办法
8497
查看次数

heredoc for Windows批处理?

有没有一种方法可以批量指定多行字符串,类似于unix shell中的heredoc.类似的东西:

cat <<EOF > out.txt
bla
bla
..
EOF
Run Code Online (Sandbox Code Playgroud)

我们的想法是从模板文件创建自定义文件.

templates batch-file heredoc

31
推荐指数
6
解决办法
2万
查看次数

用空格缩进heredocs

对于我所从事的个人开发和项目,我们使用四个空格而不是制表符.但是,我需要使用heredoc,我不能在不打破缩进流的情况下这样做.

我能想到的唯一可行的方法是:

usage() {
    cat << '    EOF' | sed -e 's/^    //';
    Hello, this is a cool program.
    This should get unindented.
    This code should stay indented:
        something() {
            echo It works, yo!;
        }
    That's all.
    EOF
}
Run Code Online (Sandbox Code Playgroud)

有一个更好的方法吗?

如果这属于Unix/Linux Stack Exchange,请告诉我.

bash spaces heredoc indentation

31
推荐指数
1
解决办法
1万
查看次数

在bash中生成脚本并将其保存到需要sudo的位置

在bash中,我可以根据本网站创建一个带有here-doc的脚本:http: //tldp.org/LDP/abs/html/abs-guide.html#GENERATESCRIPT

(
cat <<'EOF'
#!/bin/bash
#? [ ] / \ = + < > : ; " , * | 
#/ ? < > \ : * | ”
#Filename="z:"${$winFn//\//\\}
echo "This is a generated shell script."
App='eval wine "C:\Program Files\foxit\Foxit Reader.exe" "'$winFn'"'
$App
EOF
) > $OUTFILE
Run Code Online (Sandbox Code Playgroud)

如果我$OUTFILE是一个需要sudo权限的目录,我在哪里放置sudo命令或我还能做些什么来使其工作?

bash sudo heredoc

27
推荐指数
2
解决办法
6546
查看次数

这里将文档作为bash函数的参数

是否可以将此文档作为bash函数参数传递,并且在函数中将参数保留为多行变量?

以下内容:

function printArgs {
echo arg1="$1"
echo -n arg2=
cat <<EOF
$2
EOF
}

printArgs 17 <<EOF
18
19
EOF
Run Code Online (Sandbox Code Playgroud)

或者可能:

printArgs 17 $(cat <<EOF
18
19
EOF)
Run Code Online (Sandbox Code Playgroud)

我有一个here文档,我想将ssh作为执行命令提供给ssh会话,并从bash函数调用ssh会话.

bash shell arguments function heredoc

26
推荐指数
3
解决办法
1万
查看次数

如何在bash here-document中键入选项卡?

here-document的定义如下:http: //en.wikipedia.org/wiki/Here_document

如何在here-document中键入选项卡?比如这样:

cat > prices.txt << EOF
coffee\t$1.50
tea\t$1.50
burger\t$5.00
EOF
Run Code Online (Sandbox Code Playgroud)

更新:

这个问题涉及的问题:

  1. 展开制表
  2. 虽然没有扩大美元符号
  3. 将here-doc 嵌入诸如脚本之类的文件中

bash tabs heredoc

24
推荐指数
4
解决办法
2万
查看次数

bash变量扩展$ {var:+"..."}在这里 - 文档删除双引号?

我试图理解为什么Bash在使用${parameter:+word}(使用备用值)进行变量扩展时,在here-document中删除双引号(但不是单引号),例如:

% var=1
% cat <<EOF
> ${var:+"Hi there"}
> ${var:+'Bye'}
> EOF
Hi there
'Bye'
Run Code Online (Sandbox Code Playgroud)

根据手册,后面的"单词" :+用波浪扩展,参数扩展,命令替换和算术扩展处理.这些都不应该做任何事情.

我错过了什么?如何在扩展中获得双引号?

bash heredoc quoting expansion

23
推荐指数
2
解决办法
1603
查看次数

在Java中构造HTML字符串的Simple/Direct/Heredoc方式

在python中,我可以构造一个HTML字符串,而不必担心通过简单地将字符串括在三个引号中来转义像<或"这样的特殊字符,如:

html_string = """
<html>
<body>
<p>My text with "quotes" and whatnot!<p>
</body>
</html>
"""
Run Code Online (Sandbox Code Playgroud)

在Java中有类似的方法吗?

html java string heredoc convenience-methods

22
推荐指数
1
解决办法
4891
查看次数

JavaScript HERE-doc还是其他大型引用机制?

有没有一种方便的方法来引用在JavaScript中同时包含单引号和双引号的大块HTML?

有什么像HERE-doc <<EOF,多引号字符"""或自定义分隔符q{}

这个问题的任何创造性或创造性解决方案

javascript quotes heredoc

21
推荐指数
3
解决办法
1万
查看次数