Results 1 to 3 of 3

Thread: How to output html from within php?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    How to output html from within php?

    Hi all i wonder how i can output html code from with in php code after i write to a file and the .txtfile get created?

    My current code uses require 'config.txt'; method to out put the following html code
    Code:
    <html>
    <head>
    <title> MP3 Player Music and Videos</title>
    </head>
    <body>
    
    	&nbsp;</td>
    		<td align="center" width="60%">
    
    		  <object type="application/x-shockwave-flash" data="mp3player.swf?playlist=733476022.txt" width="280" height="280" wmode="transparent">
      			<param name="movie" value="mp3player.swf?playlist=ram.txt" />
      			<param name="wmode" value="transparent" />
      		</object>
      		
    		</td>
    		
    </body>
    </html>
    I wonder how i can avoid using require 'config.txt' and be able to output the above html from within my main code?Furthermore, i want to place .txt file name dynamically where it is inside $filename variable instead of above 733476022.txt. I be happy if an expert help me out here.Thanks


    Code:
    
    <?php
    
    
    
    $url[1] = "http://localhost/flash_mp3_player/mp3/01 - Saracha.mp3";
    $url[2] = "http://localhost/flash_mp3_player/mp3/13 - Gar Aya.mp3";
    $url[3] = "http://localhost/flash_mp3_player/mp3/Soroush - Yeh Donya - 02 Shoghe Nafas.mp3";
    
    
    $mycontent = "";
    if (isset($_GET["sid"]))
    {
       $allsid = explode (",",$_GET["sid"]);
       $mycontent = array();
       foreach ($allsid AS $value)
          $mycontent[] = $url[$value];
    }
    
    echo $mycontent;
    
    $filename = time() . ".txt";  
    $handle = fopen ($filename,"w+");
    
    if ($handle)
    {
      if (fwrite ( $handle,implode("\r\n",$mycontent)."\r\n") )
      {
          echo "FILE IS WRITTEN SUCCESSFULLY";
      } else
      {
           echo "ERROR IN WRITING TO FILE";
      }
      fclose ($handle);
    } else
    {
          echo "ERROR IN OPENING FILE";
    }
    
    require 'config.txt';===> i want output it from within main script and avoide useing require 'config.txt'; method!
    ?>

  2. #2
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    Re: How to output html from within php?

    You mean
    PHP Code:
    <?php



    $url
    [1] = "http://localhost/flash_mp3_player/mp3/01 - Saracha.mp3";
    $url[2] = "http://localhost/flash_mp3_player/mp3/13 - Gar Aya.mp3";
    $url[3] = "http://localhost/flash_mp3_player/mp3/Soroush - Yeh Donya - 02 Shoghe Nafas.mp3";


    $mycontent "";
    if (isset(
    $_GET["sid"]))
    {
       
    $allsid explode (",",$_GET["sid"]);
       
    $mycontent = array();
       foreach (
    $allsid AS $value)
          
    $mycontent[] = $url[$value];
    }

    echo 
    $mycontent;

    $filename time() . ".txt";  
    $handle fopen ($filename,"w+");

    if (
    $handle)
    {
      if (
    fwrite $handle,implode("\r\n",$mycontent)."\r\n") )
      {
          echo 
    "FILE IS WRITTEN SUCCESSFULLY";
      } else
      {
           echo 
    "ERROR IN WRITING TO FILE";
      }
      
    fclose ($handle);
    } else
    {
          echo 
    "ERROR IN OPENING FILE";
    }
    ?>
    <html>
    <head>
    <title> MP3 Player Music and Videos</title>
    </head>
    <body>

        &nbsp;</td>
            <td align="center" width="60%">

              <object type="application/x-shockwave-flash" data="mp3player.swf?playlist=733476022.txt" width="280" height="280" wmode="transparent">
                  <param name="movie" value="mp3player.swf?playlist=<?=$filename?>" />
                  <param name="wmode" value="transparent" />
              </object>
              
            </td>
            
    </body>
    </html>
    Stick that in one PHP file and it will do what you want, unless i have missed something, which i normaly do

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Arrow Re: How to output html from within php?

    :-)) MAny MAny thanks to u that did the trick like magic!!

Posting Permissions

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



Click Here to Expand Forum to Full Width