Solved

Exclude some code in a .php file

Posted on 2014-04-27
5
1,653 Views
Last Modified: 2014-04-28
Hello all.

I cant figure out how to exclude some code in my .php file. Its php code.

When using html i just use <!-- --> but now i cant figure out the same rhytme with php :S

Seems so easy, but i cant bing it.


HELP ME, I KEEP BEING A NAB.
0
Comment
Question by:Mike Kristensen
5 Comments
 
LVL 29

Expert Comment

by:becraig
ID: 40026289
Comments can be written

//This is a comment


Multi line comments

    /* This is a multi line comment
      Another comment on another line*/
0
 

Author Comment

by:Mike Kristensen
ID: 40026293
Hmmm. Sry. It is as soon as im working inside a state, or something like that. (What you call it?)

Look this:
$form = <<<ENDFORM
<form action=noter.php method=post>
<tr>
<td><input type=submit name=tilføj_note_l value='Tilføj_note_linje' > </td>
</tr>
</form>
ENDFORM;
echo $form;

How to exclude the <td> line? In my file its all grey text for now. Im not sure, but it seems to be the grey text i cant exclude.
0
 
LVL 9

Accepted Solution

by:
Trenton Knew earned 500 total points
ID: 40026341
If you cannot edit the region, than you may not be able to comment the line out.  It looks like you're missing your PHP opens and closers though.  The HTML inside a php would kind of not work right.  Look at this:
$form = <<<ENDFORM
/* assuming you are inside a PHP code block here, you close it with this -> */  ?>
<form action=noter.php method=post>
<tr>
<?php /*let's hide this line by opening another php code block and then commenting it out with a double slash */
//<td><input type=submit name=tilføj_note_l value='Tilføj_note_linje' > </td>
/* also need to close that block here too */ ?>
</tr>
</form>
<?php //needs to be reopened here
ENDFORM;
echo $form;
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 40026591
When you use heredoc notation, you can't simply comment out a single part of the code. You have to just delete it. Otherwise, if you need to include or exclude some part accordingly to some condition, you have to write two forms:

$form1 = <<<ENDFORM
<form action=noter.php method=post>
<tr>
<td><input type=submit name=tilføj_note_l value='Tilføj_note_linje' > </td>
</tr>
</form>
ENDFORM;
$form2 = <<<ENDFORM
<form action=noter.php method=post>
<tr>

</tr>
</form>
ENDFORM;

if (your condition here)
{
    echo $form1;
}
else
{
    echo $form2;
}

Open in new window

0
 

Author Comment

by:Mike Kristensen
ID: 40027408
Thx. I understand the system now.

Or haha. But i understand what i have to do :)
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question