Jump to content

Novice Question


fredley

Recommended Posts

that would be because you're in PHP already - you don't have to open PHP tags to echo a variable when you're already in it:

 

echo '<form method="post" action="'.$_SERVER['PHP_SELF'].'"';

 

have a read in the manual about strings and variable interpolation / concatenation.

Link to comment
https://forums.phpfreaks.com/topic/60823-novice-question/#findComment-302612
Share on other sites

I don't think you understand, this line is part of a while loop, so I can't drop out of php, i have the line

echo '<form method="post" action="<?=$_SERVER['PHP_SELF']"?>'; 

in my loop and it causes an error.

 

Yes you can drop out of PHP anytime you need to.

 

If your already in php in this line, then use

echo '<form method="post" action="'.$_SERVER['PHP_SELF'] .'">';

 

 

consider this....

<?php
$x=0;
while($x < 6)
{ ?> <!-- drop out of php in the middle of the loop -->
             <a href="someurl.html" class="<?=$x ?>" >A Link</a><br>
<?php
$x++;
} // start it back up to finish the loop

?>

 

THis is not a wonderful example, but it works. One of the great things about PHP is that you can drop in and out of it as you see fit. Those folks who have 25 lines of echo ' pure html'  can save a lot of trouble if they just drop out of php when they need to use html and back in when they need php

 

 

just for reference, <?php echo $xyz ?> is the same as <?=$xyz ?> they will do the exact same thing with a few less characters.

hope it helps

Link to comment
https://forums.phpfreaks.com/topic/60823-novice-question/#findComment-302623
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.