Questions tagged [nowdoc]

21 questions
62
votes
4 answers

Advantages / inconveniences of heredoc vs nowdoc in php

As a newbie, I have been advised to preferably use heredoc compared to too many nested codes (see Unexpected T_ELSE in php code). But I can't manage to understand if there is a significant difference between heredoc and nowdoc. What would be the…
Mathieu
  • 4,587
  • 11
  • 57
  • 112
7
votes
2 answers

sprintf argument swapping and HEREDOC

I'm trying to use sprintf on a heredoc this way. It wont work. Any idea how to solve this? $i = <<
jmenezes
  • 1,888
  • 6
  • 28
  • 44
6
votes
7 answers

Why do these Heredoc and Nowdoc cause errors?

I've already found some solutions, but can't know what happened... Example 1:
mpyw
  • 5,526
  • 4
  • 30
  • 36
3
votes
5 answers

PHP - recognize when the function was called

I'm thinking about how to find from where any function was called. The problem is that I need to find where the PHP is calling mail() function. One way will be to use register_tick_function(), but I'll need to open each file and check what is on…
martin.malek
  • 2,166
  • 2
  • 19
  • 31
2
votes
1 answer

How to include text next to php variable in heredoc text

My actual use case involves filling in javascript variable names with partial id's from php, but to illustrate the issue here's a simple example with html: $var="ello worl"; echo <<
amd_123
  • 41
  • 3
2
votes
2 answers

escaping "" when outputing to a file - nowdoc/heredoc

What I was trying to do (and could, actually but only on my local testserver) is to output a php-file with php. The problem seems to be the opening and closing tags of php. I looked up nowdoc in php.net but could not find a clue to the solution. If…
leugim
  • 564
  • 1
  • 5
  • 14
2
votes
3 answers

Can't see new lines on textarea - what could the problem be?

I have a php string with a lot of information to be displayed inside a textarea html element. I don't have access to that textarea nor to the script (if any) that generates it. $somestring = 'first line \nSecond line \nThird line.'; $somestring as…
MEM
  • 30,529
  • 42
  • 121
  • 191
1
vote
1 answer

Interpreting variables but ignoring escape sequences in PHP HEREDOC

I am trying to figure out how I can use HEREDOC syntax to interpret variables but ignore the backslash character. Or use NOWDOC syntax to allow for the interpretation of variables. An example of what I am trying to do: $title = "My title…
kojow7
  • 10,308
  • 17
  • 80
  • 135
1
vote
3 answers

PHP Print and Echo HTML

very simple question. Lol i am embarassed to ask this cause i am usually very good with php but what are the ways to display html inside of php? for example:
This will show is $flag is true
OR
rolling_codes
  • 15,174
  • 22
  • 76
  • 112
1
vote
0 answers

Nowdoc Parse error: syntax error, unexpected T_SL

$default_post = <<<'DEFAULT_POST'
johnh10
  • 4,047
  • 1
  • 18
  • 30
1
vote
1 answer

Heredoc in Laravel database seed

I'm trying to create a database seed in laravel that uses a heredoc to set an xml structure into a variable and then use that variable as one of the values in the seed: class CodeTableSeeder extends Seeder { public function run() { …
Chris Schmitz
  • 20,160
  • 30
  • 81
  • 137
0
votes
2 answers

Why can't my local PHP function see the $test variable, and how can I get its value?

I'm using the PHP HereDoc and NowDoc statements to build the web-pages in my web-site, with HereDocs for parts that need PHP variable values substituted into the web-pages, and NowDocs for parts that use the $ characters to specify jQuery statements…
user2505564
0
votes
1 answer

nowdoc inside a function

I have some PHP code that I want to convert to a function. Unfortunately the code uses nowdoc to create a format string for a sprintf() call. This poses a formatting dilemma because It means I can't indent the closing identifier to match the…
wm_g
  • 25
  • 5
0
votes
1 answer

Parsing only some variables with heredoc or nowdoc

Using heredoc or nowdoc, how could I create $sting? $x_value=2; $string='$x='.$x_value.';'; exit($string); //$x=2; PS. I am aware of the slippery slope of script like this
user1032531
  • 24,767
  • 68
  • 217
  • 387
1
2