Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6342283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:12:45+00:00 2026-05-24T20:12:45+00:00

I am trying to capture the contents of my php page using output buffering:

  • 0

I am trying to capture the contents of my php page using output buffering:

<?php

function connect() {
  $dbh = mysql_connect ("localhost", "user", "password") or die ('I cannot connect to the database because: ' . mysql_error());
  mysql_select_db("PDS", $dbh); 
  return $dbh;
}

session_start();

if(isset($_SESSION['username'])){
  if(isset($_POST['entryId'])){
    //do something
    $dbh = connect();
    $ide = $_POST['entryId'];
    $usertab = $_POST['usertable'];
    $answertable = $usertab . "Answers";
    $entrytable = $usertab . "Entries";
    $query = mysql_query("SELECT e.date, q.questionNumber, q.question, q.sectionId, a.answer FROM $answertable a, Questions q, $entrytable e WHERE a.entryId = '$ide' AND a.questionId = q.questionId AND e.entryId = '$ide' ORDER BY q.questionNumber ASC;") or die("Error: " . mysql_error());

    if($query){
      //set variables      
      $sectionOne = array();      
      while($row=mysql_fetch_assoc($query)){
    $date = $row['date'];
    $sectionOne[] = $row;   
      }
    }else{
      //error - sql failed
    }
  } 
?>

<?php
  ob_start();
?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
   <head>
   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
   <script src = "jQuery.js"></script>
   <script>
   $(document).ready(function(){
       $("#export").click(function(e){
       //post to html2pdfconverter.php
       $("#link").val("<?php echo(ob_get_contents()); ?>"); //THIS DOESN'T WORK
       $("#nm").val("Entry Report.pdf");       
       $("form#sendanswers").submit();
       }); 
   });
  </script>
  <title>Personal Diary System - Entry Report - <?php echo($date); ?></title>
  </head>
  <body>
  <h1>Entry Report - <?php echo($date); ?></h1>    
  <div id = "buttons">
  <form id = "sendanswers" name = "sendanswers" action="html2pdfconverter.php" method="post">
  <input type = "hidden" name = "link" id = "link" value = "">
  <input type = "hidden" name = "nm" id = "nm" value = "">
  <input type = "button" name = "export" id = "export" value = "Export As PDF"/>
  </form>                        
  </div>                         
  <h3>Biological Information</h3>
  <?php
     echo('<p>');                         
      $i = 0;                         
      foreach($sectionOne as &$value){
    if($i == 1 || $i == 3){
      $image = "assets/urine".$i.".png";
      echo("<br/>");
      echo($value['question']." <br/> "."<img src = \"$image\"/>");
      echo("<br/>");
    }else{
      echo($value['question'].' : '.$value['answer']);
    }
    echo("<br/>");
    $i++;
      }
     echo('</p>');      
  ?>
  </body>
</html>
<?php   
}
$contents = ob_get_contents(); //THIS WORKS    
ob_end();
?>

I assign the contents of ob to $contents using ob_get_contents(); This works, and echoing $contents duplicates the html page.

However, in my jQuery, I am trying to assign this to a hidden text field (‘link’) using:

$("#link").val("<?php echo($contents); ?>");

This doesn’t work however..And I have a feeling its because I am accessing $contents too eraly but not too sure…any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T20:12:46+00:00Added an answer on May 24, 2026 at 8:12 pm
       $("#link").val("<?php echo(ob_get_contents()); ?>"); //THIS DOESN'T WORK
    

    at the point you do that ob_get_contents call, you’ve only output about 10 lines of javascript and html. PHP will NOT reach back in time and magically fill in the rest of the document where you do this ob_get_contents().

    You’re basically ripping the page out of the laser printer the moment the page starts emerging, while the printer is still printing the bottom half of the page.

    I fail to see why you want to embed the contents of your page into an input field. If you want to somehow cache the page’s content in an input field, you can just use JS to grab the .innerHTML of $('body').

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to capture the following page using standard c# .net code. I've
I am trying to capture the following content in PHP using regular expressions: /*
I trying to capture packets using SharpPcap library. I'm able to return the packets
I am trying to capture in real time what the user enters in the
I'm trying to capture dvdauthor's output to a file. So far i found this
I'm trying to capture http request that occurs in a callback function : //
I am trying to capture urls in an html page that is being repeated
I'm trying to capture audio, using the method in this question ; with AVCaptureSession
I am using the Jquery Wysiwyg editor and I am trying to capture the
I am trying to make a php page (It's Wordpresss but mostly custom php)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.