This question already has answers here:
Reference Guide: What does this symbol mean in PHP? (PHP Syntax)
(24 answers)
Closed 7 years ago.
I've stumbled across some code that looks like it's alternate syntax for assigning something into a variable in PHP.
$VSWTags = <<<VSW
BUNCHOFHTMLANDSTUFFHERE
VSW;
This is in a Drupal site we have here at work, and I searched on PHP.net for the VSW and for the <<< I couldn't find anything. When I played with it in the console I saw that it basically is just support for bare words or something of that nature?
php > $s = <<<VSW <<< > I dont know what this is doing
<<< > but its cool
<<< > VSW;
php > print $s;
I dont know what this is doing
but its cool
php >
Does anyone know where the documentation is for this or what it's called?
This is HEREDOC - very usefull for large strings.
Related
This question already has answers here:
Reference Guide: What does this symbol mean in PHP? (PHP Syntax)
(24 answers)
Closed 3 years ago.
My company has asked me to analyse backend code for one the live websites that our company maintains. I have run into a problem. I can't quite figure what '#' is doing here in this code if(#($_SESSION['user'])){...}
I looked everywhere what this means and haven't found anything even remotely resembling this. I hope someone on this forum can help me out. Below is the entire code snippet.
if(#($_SESSION['user']))
{
$usrid=$_SESSION['user'];
$getprflimg=$db->singlerec("select img from register where
id='$usrid'");
$imgurlprl=$getprflimg['img'];
if(file_exists($url))
$imgurlprl=$siteurl."uploads/user_images/".$imgurlprl;
else
$imgurlprl=$siteurl."/uploads/user_images/no_image.png";
}
# before the variable is used to suppress the warning generated for that variable. This is also relevant to 'At' symbol before variable name in PHP: #$_POST.
This question already has answers here:
Reference Guide: What does this symbol mean in PHP? (PHP Syntax)
(24 answers)
Closed 6 years ago.
$channel =<<<_XML_;
what is meaning of above statement ?
Is XML predefined variable ?
What is the meaning of <<<
This syntax is called a heredoc. It's very convenient to enter long (usually multiline) strings without having to mess around with escaping etc.
This question already has answers here:
Reference Guide: What does this symbol mean in PHP? (PHP Syntax)
(24 answers)
Closed 9 years ago.
Previous I bumped into codes like this:
<?php
$var="hello";
?>
<?=$var?>
It simply prints out the content of $var, so... is the syntax equivalent to echo $var?
I'll also appreciate an answer pointing to a related manual page. Since the syntax is not searchable.
Yes, <?=$var?> is the same as <?php echo $var; ?>
From PHP.net manual: echo also has a shortcut syntax, where you can immediately follow the opening tag with an equals sign. Prior to PHP 5.4.0, this short syntax only works with the short_open_tag configuration setting enabled.
You can read more here.
This question already has answers here:
Reference Guide: What does this symbol mean in PHP? (PHP Syntax)
(24 answers)
Closed 8 years ago.
I am trying to include some javascript for the google analytics ecommerce tracking.
In the example code I see something like this, in which I have replaced the variables with my own.
<?php
function getTransactionJs(&$order) {
return <<<HTML
ga('ecommerce:addTransaction', {
'id': '{$order->ord_order_numner}',
'affiliation': 'Marcella',
'revenue': '{$order->total_payment}',
'shipping': '0',
'tax': '0'
});
HTML;
}
echo getTransactionJs($order);
?>
However I met with a syntax error. May I ask what is the meaning of
return <<<HTML
Thanks in advance!
It's a way to define a string on multiple lines. Your string begin juste after the <<<HTML and ends at HTML; The HTML word can be replaced by whatever you want.
See Heredoc syntax.
It’s PHP’s Heredoc syntax. I’m not a fan of it though.
As suggested read the manual, but consider not to use this kind of syntax.
To make your life easier - in most cases the problem is with text indenting.
HTML;
Must be at the start of the line not indented!
This question already has answers here:
Reference Guide: What does this symbol mean in PHP? (PHP Syntax)
(24 answers)
Closed 9 years ago.
I have been doing my Homework regarding mongodb and PHP and honestly, I'm fairly new at this and this is my first post at SO.
What does"." operator do in PHP?
For example
$cmd = "SELECT m_time,m_latency,m_length FROM pkt_tbl WHERE m_in_port=". $in_port
What does "." in .$in_port mean? How can I convert the entire syntax to mongodb?
This is my try:
$db->pkt_tbl->find(array("m_in_port=".$inport,array("m_time"=>1,"m_latency"=>1,"m_length"=>1));
Please correct my syntax and enlighten me regarding "." operator, I badly want to learn and I'm a newbie at PHP and mongodb.
That is incorrect PHP. Try:
$db->pkt_tbl->find(
array("m_in_port"=>$inport),
array("m_time"=>1,"m_latency"=>1,"m_length"=>1)
);
In PHP, . is the concatenation operator. It tells the interpreter to stick strings or variables together end-to-end. For example, "hello " . "world" is equivalent to "hello world". In the case of your example, if $in_port=10, then your line of code would be equivalent to "SELECT m_time,m_latency,m_length FROM pkt_tbl WHERE m_in_port=10";