Using PHP with HTML tags - Big confusion

Discussion in 'PHP' started by FoxIX, Oct 18, 2010.

  1. #1
    Hi all,

    I am currently attempting to add some html inline styling to php, but all I seem to get is the error:

    The original line is:

    echo htmlentities($data[0]);
    PHP:
    What I currently have (which does not work) is:

    echo "<p style=\"width:200\">"htmlentities($quote)"</p>";
    PHP:
    Any help would be gratefully appreciated!
     
    FoxIX, Oct 18, 2010 IP
  2. ramsarvan

    ramsarvan Greenhorn

    Messages:
    59
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #2
    hi,

    try this

    echo '<p style=\"width:200\">'.htmlentities($quote).'</p>';

    I think this will work.
     
    ramsarvan, Oct 18, 2010 IP
  3. FoxIX

    FoxIX Well-Known Member

    Messages:
    211
    Likes Received:
    10
    Best Answers:
    1
    Trophy Points:
    140
    #3
    Thank you. That did get rid of the error and now displays the quote, but the actual style is not presented (it is not 200px wide - still the length of the window).
     
    FoxIX, Oct 18, 2010 IP
  4. axelay

    axelay Peon

    Messages:
    54
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You need to be careful what you use
    when you output data on the screen, you can do it using apostrophes (') or quotes ("). There is a difference between them...
    echo '<p style="width:200px">PHP\'s the best</p>';
    PHP:
    or
    echo "<p style=\"width:200px\">PHP's the best</p>";
    PHP:
    You have to make sure you escape the proper character.
    In your example, you should do:
    echo '<p style="width:200px">' . htmlentities($quote) . '</p>';
    PHP:
    aXe :)
     
    axelay, Oct 18, 2010 IP
  5. FoxIX

    FoxIX Well-Known Member

    Messages:
    211
    Likes Received:
    10
    Best Answers:
    1
    Trophy Points:
    140
    #5
    Okay. That makes much more sense now AND much easier to read :) Thank you
     
    FoxIX, Oct 18, 2010 IP
  6. Griggs117

    Griggs117 Active Member

    Messages:
    73
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    85
    #6
    Any time you put 2 things together you have to use the concat operator which is the period " . " Also as stated above, when echoing HTML tags it's very important to use different types of quotes: ie echo "<a href='www.google.com'>Google</a>"; Whether you use " or ' to enclose either your php statement or your href does not matter. It's just important to never use the same one in two different cases as above, else php will get confused and not run.
     
    Griggs117, Oct 18, 2010 IP
  7. xpertdev

    xpertdev Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    This is the basic problem php developer can face at their starting phase.
    But no problem friend here is the solution.

    Here are the two ways to do this:

    1) Embed html in php

    Tip: always use single quote (') if you are embed you r html in php.

    2) make html and php separate

    Personally I prefer the second method, but it can be used based on situation.

    Hope this helps.
    Avinash
     
    xpertdev, Oct 20, 2010 IP