Asked  7 Months ago    Answers:  5   Viewed   30 times
$test= <<<EOF

....

EOF;

I have never see it before. What's it used for?

 Answers

52

This is called HEREDOC syntax, which is a way to define strings, on multiple lines, with variable interpolation.


Quoting the manual page:

Heredoc text behaves just like a double-quoted string, without the double quotes. This means that quotes in a heredoc do not need to be escaped, but the escape codes listed above can still be used. Variables are expanded, but the same care must be taken when expressing complex variables inside a heredoc as with strings.

(There is more to read, that I didn't copy-paste from the manual page)


And, as a very quick and simple example:

$a = 'World';
$string = <<<MARKER
<p>
  Hello, $a!
</p>
MARKER;
echo $string;

It will give you this output:

Hello, World!

And this HTML source:

<p>
  Hello, World!
</p>
Wednesday, March 31, 2021
 
Puneet
answered 7 Months ago
69

rename your function to something other than "goto". That is a reserved name.

Wednesday, March 31, 2021
 
Pegues
answered 7 Months ago
57

You are using curly quotes.

Replace all the “ ” and ‘ ’ to " and ' respectively.

Wednesday, March 31, 2021
 
Anand
answered 7 Months ago
45

Inspired by a previous answer. I'd suggest.

HTML

<select name="price">
    <option value="|">All (-)</option>
    <option value="400|1000">Rs.400 to Rs.1,000 (3)</option>
    <option value="1000|2000">Rs.1,000 to Rs.2,000 (6)</option>
    <option value="2000|4000">Rs.2,000 to Rs.4,000 (1)</option>
    <option value="4000|">Rs.4,000+ (1)</option>
</select> 

PHP

<?php

function get_numeric($val) { 
  if (is_numeric($val)) { 
    return $val + 0; 
  } 
  return false; 
} 

$price_selected = isset($_REQUEST['price']) && trim($_REQUEST['price'])!="" ? $_REQUEST['price'] : "|"; // sets a default value

list($lower, $upper) = array_map('get_numeric',explode('|', $price_selected, 2));

var_dump($lower); // false when there's no lower limit

var_dump($upper); // false when there's no upper limit

?>
Friday, May 28, 2021
 
mgraph
answered 5 Months ago
81

You need to make sure that the newly installed php command is executed, not the default one.

Add the folder where the correct php binary resides as the first item to the $PATH environment variable.

Saturday, May 29, 2021
 
oroshnivskyy
answered 5 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :