Grabbing only HTML div from php file through jQuery GET - php

I have a PHP file which might contain lot of PHP tags, scripts and HTML.
I need to get only HTML div inside the php file. The file contain lot of <?php > tags. I want to ignore those tags and to get only HTML from the page using jQuery.get().
Is it possible to do this?

When you open a .php file in your browser, the server executes the PHP files and only gives HTML (+javascipt +css) back. JavaScript is then executed in your browser and you won't have any <?php ?> tags inside. Therefore you can simply use jQuery selectors.

Related

How to print an html file with textarea in it into another textarea without being parsed by the browser?

I want to edit my php or html files on the server without logging in. I wrote a php file to import the file contents that I want to edit. The file contents will be printed in a textarea.
It does work. But, when I import a file with textarea, the browser parses the </textarea> from the file as its end part of the textarea. And the rest parts after will also be parsed, too.
Is there any methods to prevent the browser from parsing the file?
The HTML inside your textarea needs to use HTML Entities instead of the actual symbols. That way it won't be parsed.. so that's something like this:
<html> ... </html> <!-- no entities -->
<html> ... </html> <!-- entities -->
I bet there's a lot of functions that can help you with this, like htmlentities() or some JavaScript equivalent, that link leads to css-tricks where a really simple JS one is. JS doesn't have a native one, afaik.
Your PHP mustn't be executed, but as Progman stated:
When the source code is added to the content of the textarea (with
functions like file_get_contents()), it is not parsed by the PHP
interpreter. So it is not required to switch to a .html file to
prevent any PHP executions (there is none).
So, that solves this issue.

embed a php file from external site, just as text / html

I have a php file on a website (example: https://www.site1.com/script.php).
This script outputs some html, basically just text formatted with <h2>, <p> and so on.
I need to put this text inside a div, in a remote web page on another site (example: https://www.site2.com/page.php), then style it with css.
I don't need to load or execute script.php code, but just its "output", as you can see opening the php file from the browser
Alternative solutions than using "include" and allow_url_include in the php.ini?
just used:
echo file_get_contents("https://www.site1.com/script.php");

While loading data from a file php runs HTML code in the file. How to ignore it

One of my file is read by php and loaded on the Web UI. But if the file contains HTML tags, it interprets and disturbs the whole UI.
How to ignore the HTML tags while reading the file contents.
I am using following code to read file contents:
readfile($name);
I think what you are looking for is htmlspecialchars function.
e.g. echo htmlspecialchars($stringFile);
If you want to strip all html tags, check strip_tags function.

How to display php file output inside a html div?

Alright, so I'm trying to embed a php script that outputs a gallery of images onto my html div container. However, after an hour or so of searching I'm coming up clueless.
http://craftedbyfrank.com/test/instagram.php
That's the link to the php gallery script.
I want to display it onto the main page inside that div.
[REMOVED] - thanks!
I've tried the following, but I believe it's just wrong. I get no output.
<div id="container">
<?php include "instagram.php"; ?>
</div>
I'm trying to avoid actually pasting the php script into the html file.
php is not being parsed on your server. If you view the html source you see the actual php code you are using to include the file. Make sure that php is installed or you're not embedding the php from a cms that's encoding your tags.
You could possibly use AJAX to get the result from the PHP file and write to the containing div.
$.ajax({
type:'GET',
url:'http://craftedbyfrank.com/test/instagram.php',
data:'',
success: function(data){
$('#container').html(data);
}
});
You would possible need to adjust to get your fancy box plugin to work.
As #vletech suggested you can use AJAX to get the result from the php file.
However the main reason why it does not work is because you are trying to execute the php script inside an .html file: e.g. your page loads on - /test/index.html. In order to work the file has to be with a .php extension.

PHP include statement within CDATA tag

I am generating a KML file (which is XML formatted for a Google Map)
Within the infowindow section of the XML file is a CDATA tag.
So when the infowindow is opened on the map, the data within can be formatted with HTML tags.
Here is what I need to do. I need to have a PHP include statement within this cdata section.
I am trying to place the following within the CDATA tag,
<? include("http://www.yahoo.com"); ?>
However what I see when the page loads is:
<![CDATA[<div>
<? include("http://www.yahoo.com"); ?>
</div>
]]>
How can I get this corrected?
Thanks,
If the file has a .kml extension, you'll need to tell your web server to use PHP to serve that file extension. Something like this would do it in Apache:
AddType application/x-httpd-php .kml
If it's a .php file, my suspicion is that PHP's sort tags are disabled, and that you need to use <?php instead of <?. There's nothing really special about a CDATA tag that'd break PHP.

Categories