Jump to content

php emedded in html attributes/tags


WesleyA

Recommended Posts

Hi WesleyA.

There are many websites which are dedicated for PHP coding. For example Tutorialspoint.com , codeacademy.com, and specially w3schools. You can get any possible information about PHP here.

Good Luck.

Link to comment
Share on other sites

I will give an example. The code is a loop, but it doesn't grab the column from the css style sheet.

    <?php for ($i = 1; $i <= 4 ; $i++ ) { 
    $var = $i;
    var_dump($var)
     ?>

    <span class="<?php $var; ?>"  >

    </span>

     <?php  } ?>

changing $var in to something else or renaming the css classes does also not seem to work.

 

is the code as used above good? I'm not sure how to embed php in html attributes, what are the rules?

Link to comment
Share on other sites

Please bear in mind when you use inline techniques like these not to mix up your quote. if for instance you were embedding in somethign like <a href="http://www.'<?php echo $thelink; ?>' ">

Ooohhh no you wouldn't, you would only use single quotes to separate php string from php variable

 

echo '<a href="http://www.'.$thelink.'">';

 

With non php html inserting php using <a href="http://www.<?php echo $thelink; ?>"> is fine.

Edited by dsonesuk
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...