Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php comment

// This is a single-line comment

# This is also a single-line comment

/*
This is a multiple-lines comment block
that spans over multiple
lines
*/
Comment

php comment

<?php
// This is a single-line comment

# This is also a single-line comment
  
/*
This is a multiple-lines comment block
that spans over multiple
lines
*/
  
// You can also use comments to leave out parts of a code line
$x = 5 /* + 15 */ + 5;
echo $x;
?>
Comment

comment in php

<?php
// Author : https://www.codedweb.org/
// This is a single-line comment
# This is also a single-line comment in unix and linux
  
/*
This is a Multi-lines comment block
by this way you can add muliple lines on it. 
lines
*/
  
// You can also use comments to leave out parts of a code line
$var = 2 /* + 12 */ + 2;
echo $var;
?>
Comment

php function comment

/**
 * Does something interesting
 *
 * @param Place   $where  Where something interesting takes place
 * @param integer $repeat How many times something interesting should happen
 * 
 * @throws Some_Exception_Class If something interesting cannot happen
 * @author Monkey Coder <mcoder@facebook.com>
 * 
 * @return Status
 */ 
Comment

Ways to write comments in PHP

/*There are two types of comments:
1) Spans over multiple lines - Multiple-line comment
2) Spans over one line only - Sinlge-line comment
*/

/* There are two ways to write a single-line comment:
1) Using double slash
2) Using the hash tag
*/

// This is an example of single-line comment using double slash
# This is an example of single-line comment using hash tag

/*There is only one way of using multiple line comments, startin with the 
slash and asterisk respectively, and ending with asterisk and slash 
respectively */ 
Comment

comment in php


<?php
 /*
    echo 'This is a test'; /* This comment will cause a problem */
 */
?>

Comment

php comment

1. /* Comment */
2. //Comment
3. #comment
Comment

comments in php

//For a single line comment use //:
//this is a comment too
//for multi-line comments use /* and */:
/* <--start of multi-line comment
this is a comment

this is a comment too (end of multi-line comment)-->*/
Comment

comment in php


<?php
    echo 'This is a test'; // This is a one-line c++ style comment
    /* This is a multi line comment
       yet another line of comment */
    echo 'This is yet another test';
    echo 'One Final Test'; # This is a one-line shell-style comment
?>

Comment

php proper function comments

/**
 * This function compiles a message that tells you how great coffee is
 *
 * @param string  $compliment A nice word to describe coffee 
 * @param integer $score      A score out of 10
 */
Comment

comment php

// This is a single-line comment
# This is also a single-line comment
/*
This is a multiple-lines comment block
that spans over multiple
lines
*/
Comment

how to make a comment in php

// single line comment
/* multi line comment
hello
*/
Comment

comment in php


it's perhaps not obvious to some, but the following code will cause a parse error! the ?> in //?> is not treated as commented text, this is a result of having to handle code on one line such as <?php echo 'something'; //comment ?>

<?php
if(1==1)
{
    //?>
}
?>

i discovered this "anomally" when i commented out a line of code containing a regex which itself contained ?>, with the // style comment.
e.g. //preg_match('/^(?>c|b)at$/', 'cat', $matches);
will cause an error while commented! using /**/ style comments provides a solution. i don't know about # style comments, i don't ever personally use them.
Comment

comment in php


A nice way to toggle the commenting of blocks of code can be done by mixing the two comment styles:
<?php
//*
if ($foo) {
  echo $bar;
}
// */
sort($morecode);
?>

Now by taking out one / on the first line..

<?php
/*
if ($foo) {
  echo $bar;
}
// */
sort($morecode);
?>
..the block is suddenly commented out.
This works because a /* .. */ overrides //. You can even "flip" two blocks, like this:
<?php
//*
if ($foo) {
  echo $bar;
}
/*/
if ($bar) {
  echo $foo;
}
// */
?>
vs
<?php
/*
if ($foo) {
  echo $bar;
}
/*/
if ($bar) {
  echo $foo;
}
// */
?>

Comment

how to create comments in php


Answer: Use the Syntax "// text" (single line) and "/* text */"
(multi-line)
Comment

php docs comments

/**
 * Summary.
 *
 * Description.
 *
 * @since x.x.x
 *
 * @see Function/method/class relied on
 * @link URL
 * @global type $varname Description.
 * @global type $varname Description.
 *
 * @param type $var Description.
 * @param type $var Optional. Description. Default.
 * @return type Description.
 */
Comment

comments in php

//
/*
*/
Comment

comment in php


It is worth mentioning that, HTML comments have no meaning in PHP parser. So,

<!-- comment
<?php echo some_function(); ?>
-->

WILL execute some_function() and echo result inside HTML comment.
Comment

comment in php


Notes can come in all sorts of shapes and sizes. They vary, and their uses are completely up to the person writing the code. However, I try to keep things consistent in my code that way it's easy for the next person to read. So something like this might help...

<?php

//======================================================================
// CATEGORY LARGE FONT
//======================================================================

//-----------------------------------------------------
// Sub-Category Smaller Font
//-----------------------------------------------------

/* Title Here Notice the First Letters are Capitalized */

# Option 1
# Option 2
# Option 3

/*
 * This is a detailed explanation
 * of something that should require
 * several paragraphs of information.
 */
 
// This is a single line quote.
?>

Comment

comment in php


Comments in PHP can be used for several purposes, a very interesting one being that you can generate API documentation directly from them by using PHPDocumentor (http://www.phpdoc.org/).

Therefor one has to use a JavaDoc-like comment syntax (conforms to the DocBook DTD), example:
<?php
/**
* The second * here opens the DocBook commentblock, which could later on<br>
* in your development cycle save you a lot of time by preventing you having to rewrite<br>
* major documentation parts to generate some usable form of documentation.
*/
?>
Some basic html-like formatting is supported with this (ie <br> tags) to create something of a layout.
Comment

comment in php


Be careful when commenting out regular expressions.

E.g. the following causes a parser error.

I do prefer using # as regexp delimiter anyway so it won't hurt me ;-)

<?php 

/*

 $f->setPattern('/^d.*/');

*/

?>

Comment

comment in php


Comments do NOT take up processing power.

So, for all the people who argue that comments are undesired because they take up processing power now have no reason to comment ;)

<?php

// Control
echo microtime(), "<br />"; // 0.25163600 1292450508
echo microtime(), "<br />"; // 0.25186000 1292450508

// Test
echo microtime(), "<br />"; // 0.25189700 1292450508
# TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST
# .. Above comment repeated 18809 times ..
echo microtime(), "<br />"; // 0.25192100 1292450508

?>

They take up about the same amount of time (about meaning on a repeated testing, sometimes the difference between the control and the test was negative and sometimes positive).
Comment

comment in php


<h1>This is an <?php # echo 'simple';?> example</h1>
<p>The header above will say 'This is an  example'.</p>
Comment

comment in php


MSpreij (8-May-2005) says  /* .. */ overrides //  
Anonymous (26-Jan-2006) says // overrides /* .. */

Actually, both are correct. Once a comment is opened, *everything* is ignored until the end of the comment (or the end of the php block) is reached.

Thus, if a comment is opened with: 
   //  then /* and */ are "overridden" until after end-of-line 
   /*  then // is "overridden" until after */
Comment

php comment

// one line comment
Comment

PREVIOUS NEXT
Code Example
Php :: php string interpolation 
Php :: laravel APP_ENV config 
Php :: db transaction laravel 
Php :: get current day php 
Php :: wpml get site url 
Php :: laravel mail send 
Php :: add javascript to functions.php 
Php :: how to get previous date in laravel 
Php :: laravel routes not working on production server 
Php :: php check if int is odd 
Php :: Custom Font Laravel 
Php :: php string search in array 
Php :: null value in php 
Php :: clear cache symfony 
Php :: select multiple option in laravel 
Php :: php unique associative nested array by value 
Php :: convert datetime to string in php 
Php :: delete and return response and nocontent laravel 
Php :: PHP MySQL Use The WHERE Clause 
Php :: laravel upload file to aws s3 
Php :: maatwebsite/excel package 5.2 laravel 
Php :: convert multdimentional array in array in php 
Php :: how to clear php form data after submit 
Php :: create role spatie 
Php :: Notice: Array to string conversion php 
Php :: laravel request has 
Php :: get file request in laravel 
Php :: wp rest api acf fields 
Php :: array length php 
Php :: wordpress rename post format 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =