Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Parsing the HTML generated by another PHP script is rather hackish. If you are developing a new site, at a minimum, you should divide your PHP script into functions and then, for AJAX requests, only call the necessary functions.</p> <p>Even if you are working on an existing, complex site, keep in mind that jQuery's <a href="http://api.jquery.com/load/" rel="nofollow">.load()</a> allows you to insert a specific fragment of the server's response into the document, discarding the rest:</p> <pre><code>$('#content').load('script.php #content'); </code></pre> <hr> <p>That said, what you are asking about is possible:</p> <ul> <li><p>PHP's <a href="http://www.php.net/manual/en/ref.outcontrol.php" rel="nofollow">output control</a> functions allow you to capture a script's output as a string, which you can parse using str_get_html(). To make this work, you would have to include the existing PHP script. Note that any script you include will have access to global functions and variables, superglobals, and classes.</p> <p><strong>Warning:</strong> Make sure you check the requested filename against a whitelist of specific files to prevent <a href="http://cwe.mitre.org/data/definitions/98.html" rel="nofollow">file inclusion attacks</a>. Merely blacklisting URLs and disabling allow_url_fopen are not sufficient to protect your site.</p> <pre><code>ob_start(); require $filename; // might have to be outside of a function $html = str_get_html(ob_get_clean()); </code></pre></li> <li><p>Alternatively, you could have the AJAX script make its own HTTP request using either <a href="http://www.php.net/manual/en/function.file-get-contents.php" rel="nofollow">file_get_contents()</a> or <a href="http://www.php.net/manual/en/book.curl.php" rel="nofollow">cURL</a> (specifying an absolute URL, not a filename). Unless you configure your web server otherwise, this internal request would show up in your web server's access log as coming from 127.0.0.1 or your web server's IP address.</p></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload