1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How do I include html script in PHP?

Discussion in 'PHP' started by Imozeb, Mar 4, 2010.

  1. #1
    How do I include html script in a PHP variable for a link? For example I want to create a variable and store <a href=""> html script in it. How can I do this?

    This is what I have tried:

    PHP Code:
    
    $user = "<a href="www.example.com/folder/file.php">guy</a>";
    echo("$user");
    
    Code (markup):
    It just printed the a href=www.example.. text to the screen. :( And...

    Is there anyway I can use PHP to change the <title> tag in my html script to a PHP varible output?

    Thanks!

    ~imozeb :)
     
    Imozeb, Mar 4, 2010 IP
  2. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #2
    You need to use different quote marks, try this

    
    
    $string = '<a href="">Link</a>';
    
    
    Code (markup):
    When you use single quotes you can't use variables in the string either.
     
    HuggyStudios, Mar 4, 2010 IP
  3. jimmy4feb

    jimmy4feb Peon

    Messages:
    56
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    This will be like this:

    $user = "<a href='http://www.website.com/directory/page.php'>your text</a>";
    echo $user;

    Just look at quotes

    Thanks,

    Jimmy
     
    jimmy4feb, Mar 4, 2010 IP
  4. Imozeb

    Imozeb Peon

    Messages:
    666
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks guys!

    One more thing, is there anyway I can use PHP to change the <title> tag in my html script to a PHP varible output?
     
    Imozeb, Mar 4, 2010 IP
  5. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #5
    
    <?php
    $title = "Digital Point";
    ?>
    <html>
    <head>
    <title><?php echo $title; ?></title>
    PHP:
    ...
     
    danx10, Mar 4, 2010 IP
  6. Narrator

    Narrator Active Member

    Messages:
    392
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    80
    #6
    If you want to use double quotes then you need the escape the ones in the string with \
    
    $user = "<a href=\"www.example.com/folder/file.php\">guy</a>";
    echo("$user");
    
    PHP:
    If you use single quotes on the echo it wont display the variable
    
    echo '$user';
    
    PHP:
    will just display $user not what the variable is
     
    Narrator, Mar 4, 2010 IP
  7. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #7
    @ Narrator & Imozeb

    Theirs no need to use parenthesis around the echo, as its optional and doesnt make any difference functionality wise. Also the quotes around echo'ing a variable are also uneeded (in this case).

    Furthermore instead of escaping the OP could also look into using heredoc syntax as an alternative approach:

    http://www.phpf1.com/tutorial/php-heredoc-syntax.html
     
    danx10, Mar 4, 2010 IP
    Narrator likes this.
  8. Narrator

    Narrator Active Member

    Messages:
    392
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    80
    #8

    Nice tip! Never seen that before thanks
     
    Narrator, Mar 4, 2010 IP
  9. mehmetm

    mehmetm Well-Known Member

    Messages:
    134
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #9
    hey, that's really nice and interesting one. thanks for that useful tip!
     
    mehmetm, Mar 4, 2010 IP
  10. varundbest

    varundbest Active Member

    Messages:
    279
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #10
    Thanks! I also needed it!
     
    varundbest, Mar 4, 2010 IP
  11. killaklown

    killaklown Well-Known Member

    Messages:
    2,666
    Likes Received:
    87
    Best Answers:
    0
    Trophy Points:
    165
    #11
    html should never be done inside an echo, thats poor programing.
     
    killaklown, Mar 4, 2010 IP
  12. lightingsale

    lightingsale Guest

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Oddly enough this helps out with a question I had...thanks!
     
    lightingsale, Mar 9, 2010 IP
  13. TYPELiFE

    TYPELiFE Peon

    Messages:
    109
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Hear, hear!
     
    TYPELiFE, Mar 9, 2010 IP
  14. fibi

    fibi Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Have a look at GenericFrame, there are much more powerful components. And you can insert them in the same way as HTML...

    Example:
    <?
    echo "<Button/>";
    echo "<DataGrid/>";
    ...
    ?>

    But it has single line of code components like Tree, DataGrid, Slider and so on...
    You can check the GF Explorer to see the components in action at lab.generiframe.com
     
    fibi, Mar 9, 2010 IP
  15. amitash

    amitash Well-Known Member

    Messages:
    399
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    125
    #15
    use:

    
    <?php
    echo 'HTML CODE HERE';
    ?>
    
    Code (markup):
    or


    
    <?php
    print 'HTML CODE HERE';
    ?>
    
    Code (markup):
    or


    
    <?php
    include ('htmlfile.html');
    ?>
    
    Code (markup):
     
    amitash, Mar 9, 2010 IP
  16. friendliness86

    friendliness86 Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #16
    you can write php program and can embedded the html tags. to learn more you can visit to www.w3schools.com
     
    friendliness86, Mar 9, 2010 IP