SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2013
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    echo html code in php

    Hello guys,staright to my problem. i have a html code as below:

    HTML Code:
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <script src="graph/enhance.js" type="text/javascript"></script>
    <script src="graph/excanvas.js" type="text/javascript"></script>
    <script src="graph/jquery.min.js" type="text/javascript"></script>
    <script src="graph/visualize.jQuery.js" type="text/javascript"></script>
    <link href="graph/basic.css" rel="stylesheet" type="text/css" />
    <link href="graph/visualize.css" rel="stylesheet" type="text/css" />
    <link href="graph/visualize-light.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
    
    
    .dwpeAd {
    	color: #333;
    	background-color: #F4F3Ea;
    	position:fixed;
    	right: 20px;
    	top: 20px;
    	padding: 5px;
    }
    
    .visualize { 
    	margin: 20px 0 0 30px; 
    }
    		
    
    </style>
    <script type="text/xml">
    
    <oa:widgets>
      <oa:widget wid="2281525" binding="#jQueryVisualizeChart" />
    </oa:widgets>
    
    </script>
    </head>
    
    <body>
    <script type="text/javascript">
    
       	$(function(){
    		 $('table').visualize({type: 'line', height: '300px', width: '420px', appendTitle : true, lineWeight : 8, colors : ['#b3c3f4','#39007a','#a4deab','#49a7c0','#8d10ee','#5a3b16','#26a4ed','#f45a90','#e9e744']}).appendTo('#jQueryVisualizeChart').trigger('visualizeRefresh');
    
    		});
    	 	
    </script>
    <div id="jQueryVisualizeChart"></div>
    <br />
    <table>
      <caption>
        Student Information
      </caption>
      <thead>
        <tr>
          <td></td>
          <th scope="col">Attd</th>
          <th scope="col">Quiz1</th>
          <th scope="col">Quiz2</th>
          <th scope="col">Quiz3</th>
          <th scope="col">Quiz4</th>
          <th scope="col">Test1</th>
          <th scope="col">Test2</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <th scope="row">Mary</th>
          <td>190</td>
          <td>160</td>
          <td>40</td>
          <td>120</td>
          <td>30</td>
          <td>70</td>
          <td>70</td>
        </tr>
     
      </tbody>
    </table>
    
    </body>
    </html>
    i tried to echo it like this but it's not working:

    PHP Code:

    <?php
    echo '
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <script src="graph/enhance.js" type="text/javascript"></script>
    <script src="graph/excanvas.js" type="text/javascript"></script>
    <script src="graph/jquery.min.js" type="text/javascript"></script>
    <script src="graph/visualize.jQuery.js" type="text/javascript"></script>
    <link href="graph/basic.css" rel="stylesheet" type="text/css" />
    <link href="graph/visualize.css" rel="stylesheet" type="text/css" />
    <link href="graph/visualize-light.css" rel="stylesheet" type="text/css" />
    <style type="text/css">


    .dwpeAd {
        color: #333;
        background-color: #F4F3Ea;
        position:fixed;
        right: 20px;
        top: 20px;
        padding: 5px;
    }

    .visualize { 
        margin: 20px 0 0 30px; 
    }
            

    </style>
    <script type="text/xml">

    <oa:widgets>
      <oa:widget wid="2281525" binding="#jQueryVisualizeChart" />
    </oa:widgets>

    </script>
    </head>

    <body>
    <script type="text/javascript">

           $(function(){
             $("table").visualize({type: "line", height: "300px", width: "420px", appendTitle : true, lineWeight : 8, colors : ["#b3c3f4","#39007a","#a4deab","#49a7c0","#8d10ee","#5a3b16","#26a4ed","#f45a90","#e9e744"]}).appendTo("#jQueryVisualizeChart").trigger("visualizeRefresh");

            });
             
    </script>
    <div id="jQueryVisualizeChart"></div>
    <br />
    <table>
      <caption>
        Student Information
      </caption>
      <thead>
        <tr>
          <td></td>
          <th scope="col">Attd</th>
          <th scope="col">Quiz1</th>
          <th scope="col">Quiz2</th>
          <th scope="col">Quiz3</th>
          <th scope="col">Quiz4</th>
          <th scope="col">Test1</th>
          <th scope="col">Test2</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <th scope="row">Mary</th>
          <td>190</td>
          <td>160</td>
          <td>40</td>
          <td>120</td>
          <td>30</td>
          <td>70</td>
          <td>70</td>
        </tr>
     
      </tbody>
    </table>

    </body>
    </html>'
    ;
         
    ?>
    any suggestion?

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,313
    Mentioned
    178 Post(s)
    Tagged
    8 Thread(s)
    any suggestion?
    Yup, don't echo it
    You can also include arbitary HTML in a PHP file outside of the <?php ?> tags

  3. #3
    SitePoint Zealot
    Join Date
    Jan 2013
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Pullo View Post
    Yup, don't echo it
    You can also include arbitary HTML in a PHP file outside of the <?php ?> tags
    for some purpose i need to echo it. any suggestion IF i want to echo it?

  4. #4
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,810
    Mentioned
    141 Post(s)
    Tagged
    0 Thread(s)
    use HEREDOC or store it in an external file and read it from that file or include it in your script where needed.

    PHP Code:
    $html <<< HTML
      // your HTML code here
    HTML; 
    PHP Code:
    $html file_get_contents('external.html'); 
    PHP Code:
    include('external.html'); 
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  5. #5
    SitePoint Zealot
    Join Date
    Jan 2013
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    use HEREDOC or store it in an external file and read it from that file or include it in your script where needed.

    PHP Code:
    $html <<< HTML
      // your HTML code here
    HTML; 
    PHP Code:
    $html file_get_contents('external.html'); 
    PHP Code:
    include('external.html'); 
    Hello cpradio, thanks for the suggestion, but i still want to echo it if possible instead of using include because i need to change the content of the table inside the html code from the database.

  6. #6
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,810
    Mentioned
    141 Post(s)
    Tagged
    0 Thread(s)
    Then your best bet is either option 1 or 2, both give you a variable that you can later manipulate/echo
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  7. #7
    SitePoint Member
    Join Date
    Sep 2007
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Marvin_G View Post
    Hello cpradio, thanks for the suggestion, but i still want to echo it if possible instead of using include because i need to change the content of the table inside the html code from the database.
    echo the html line by line. it will take time to code the whole html page, but at the long run it will make it easy for you to manipulate your variable.

  8. #8
    SitePoint Enthusiast
    Join Date
    Oct 2012
    Location
    Republic of Ireland
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Marvin_G View Post
    for some purpose i need to echo it. any suggestion IF i want to echo it?
    On those occasions when I have really needed to echo HTML, I have found that the string will not work when it is encapsulated with single quotes, in which case, using double quotes for the string, I would either escape the HTML double quotes with slashes or else use single quotes. (Since I live in mortal terror of the mark-up gnomes, I take great pains to mollify the little devils with consistent use of double quotes in my HTML mark-up.) Taking the <head> section of your page as a for instance, I would do this:
    PHP Code:
    $head "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n<title>Untitled Document</title>\n<script src=\"graph/enhance.js\" type=\"text/javascript\"></script>\n<script src=\"graph/excanvas.js\" type=\"text/javascript\"></script>\n<script src=\"graph/jquery.min.js\" type=\"text/javascript\"></script>\n<script src=\"graph/visualize.jQuery.js\" type=\"text/javascript\"></script>\n<link href=\"graph/basic.css\" rel=\"stylesheet\" type=\"text/css\" />\n<link href=\"graph/visualize.css\" rel=\"stylesheet\" type=\"text/css\" />\n<link href=\"graph/visualize-light.css\" rel=\"stylesheet\" type=\"text/css\" />\n\n<style type=\"text/css\">\n.dwpeAd {color: #333; background-color: #F4F3Ea; position:fixed; right: 20px; top: 20px; padding: 5px;}\n.visualize {margin: 20px 0 0 30px;}\n</style>\n\n<script type=\"text/xml\">\n\n<oa:widgets>\n\t<oa:widget wid=\"2281525\" binding=\"#jQueryVisualizeChart\" />\n</oa:widgets>\n\n</script>\n</head>"
    Then I would call that string in the template like this before proceeding to mark up the <body> section in the conventional manner:
    PHP Code:
    <?php echo $head?>
    Then I would ask myself why am I putting the templating engine to such trouble when, as others have suggested, HTML mark-up should be kept separate from PHP code where possible.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •