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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.