Save contents of iFrame to html file? - php

I am building a rich text editor using JavaScript and an editable iFrame, and I am wondering how I can use php to save the contents of the iframe to an html file.

WARNING The link http://simple.procoding.net/2008..... provided by iWantSimpleLife generates a Javascript Obfuscation alert. That site may be infected.

Correct me if I'm wrong, but isn't an iframe basically a page you're retrieving ?
If so, then file_get_contents ( http://php.net/manual/fr/function.file-get-contents.php ) should do the trick.

First, With Javascript copy the contents of the Html text of the iframe and then paste them to text in a textarea.
Then submit the text area contents to PHP script that safe it in a text file with html extension on your webserver.
Recall file system manual of PHP
http://www.php.net/manual/en/ref.filesystem.php

Use javascript to get the content. http://simple.procoding.net/2008/03/21/how-to-access-iframe-in-jquery/
This took me about 5 minutes to Google.

Related

How to display a text file hosted on another server inside a Blogger post

I need to read a text file on a server and display its content in a blog post on Blogger. The text file is a result of a simple download counter and contains a number. The problem is the Blogger does not support PHP codes in a post. My current solution is to use OBJECT tag to call PHP script that displays the text file content with ECHO. It works. But the result is displayed inside a small frame and I can't apply CSS style to it or align it properly with the existing text. Is there another way? I understand it can be done with AJAX call but my scripting knowledge is basic and I wouldn't know where to begin. Help would be appreciated.
To display the result in the blog I used this code:
<p>File test.zip downloaded
<object type="text/plain"
data="http://example.com/statistics.php?dname=test"
width="30" height="30"></object> times</p>
EDIT: I have tried to follow #Toni suggestion but it only leads to more questions. Looks like Ajax call is way beyond my current level of knowledge. Sorry and thank you again.
Here is what I'm currently trying. I have moved the text that goes with the counter inside PHP file so the script now returns a string like "file has been downloaded 8 times" instead of just number "8". Also instead of OBJECT tag I'm using IFRAME.
<iframe src="http://example.com/mystats.php?dname=test"
frameborder="0" border="0" cells pacing="0" height="30"></iframe>
The iframe seems to be easier to style. If I can't figure out how to find which CSS is applied to a blog post and how to apply it to iframe, I can at the minimum mimic the style by using similar font.
You can use javascript with your blogger web-site.
Using javascript on your web-page, you can invoke a GET request to your PHP code and get the data you want, to display it on your web-page.
Below, there are links, to help you with this task:
How to invoke GET request in vanilla JavaScript
Invoking GET with jQuery
Use JavaScript to alter text dynamically
I made it work with JavaScript! Here is how. Server side PHP script reads and echoes a text file inside document.write().
<?php
$varcontent = #file_get_contents('yourtextfile.txt');
echo 'document.write("'.$varcontent.'")';
?>
The resulting string looks like this:
document.write("your text file content here")
Inside the Blogger post add the JavaScript code with the PHP script file as a source:
<script type="text/javascript"
src="http://example.com/yourfile.php">
</script>
Done! The content of your text file is displayed and styled with your current CSS.

Display XML in texteditor (eg. tinymce,Jquery Editor) PHP

I am using Jquery text editor. I copy and paste the XML as given below in texteditor
<shoes>
<shoe>
<shouename>Shoue</shouename>
</shoe>
</shoes>
Then I click on save and the XML saved in Mysql DB. Then when I edit the same I see "Shoue" in texteditor field. But i want to show it as it is as below in texteditor
<shoes>
<shoe>
<shouename>Shoue</shouename>
</shoe>
</shoes>
I think texteditor endering the XML with HTML.
How can I show XML as it is in texteditor using PHP. So that I could edit the XML and save.
try htmlspecialchars() and read about XSS - you should use this function always when you want output user's data on HTML page.
As variant, try Twig templates engine - very simple and have built-in escaping.

Displaying PDF file in a div or iFrame

Is there any way i can load PDF file (its contents) in a div or iFrame?
I have a bunch of PDF files on a server and, ideally, i need to have a button 'Show file' on a page, clicking on which will load the contents of selected file in a div(iFrame).
You can also use google pdf view by using iframe on your page :
<iframe src="http://docs.google.com/gview?url=http://infolab.stanford.edu/pub/papers/google.pdf&embedded=true" style="width:600px; height:500px;" frameborder="0"></iframe>
Instead of this in above code :
http://infolab.stanford.edu/pub/papers/google.pdf
Use your own PDF file path.
You can view the demo here.
http://googlesystem.blogspot.in/2009/09/embeddable-google-document-viewer.html
It's just a suggestion. No downvotes please.
Google's gview is sometimes unresponsive and given 204 status. Here is the best free alternative.
https://stackoverflow.com/a/66548544/2078462

how to extract all image urls from a html source and download them using curl?

I am using curl to get the images from html source code of an external webpage. I am getting img original='imageurl' on view page source in Firefox. But when i select the particular images then it shows img src='imageurl' on view selection source in in Firefox.
How can I get this type of image using curl?
Currently I am using regex to get the image:
preg_match_all('/<img[^>]+>/i',$output, $result);
print_r($result);
But it doesn't display any image.
I am very confused about what to do here. Anyone have any thoughts?
I am very confused about what to do here.
The confusion probably results from that you use your webbrowser to view the source of an URL. Even if it's often the case that the source of the page displayed by the webbrowser is the data that curl would return as well, this is not always the case.
Especially the Firefox feature view selection source will not display that selection from the original resource, but often something else. To prevent that, you need to disable javascript in your Firefox browser­Docs. Because often documents are modified with javascript and you want to see the original, not the modification because curl is not able to run javascript, it can only get "the original".
Anyone have any thoughts?
Disable javascript in your browser.
Reload the page.
Locate the fragment of the HTML-source-code you're interested in.
Write it down, e.g. into a string.
Request the page with CURL. Output the source.
Locate that string in there. If it's not in there, search the curl request result for the string you're interested and use that instead.
Write a regular expression that is able to obtain what you need from that string.
Use that regular expression in your program then.
Your web browser is reformatting the HTML according to how it understands/parses the HTML page.
When you choose "View Page Source" it shows you the original source code served from the server.
When you select content and choose "View Selection Source" it shows what the browser has parsed into DOM (what the browser understands) for the selected content.
I am guessing you're using Firefox
If you are attempting to use cURL to process the HTML served from the server, you must not look at "View Selection Source" of the page, always refer to "View Page Source"..
Ultimately
You should rather refer to the ACTUAL result from cURL
For example:
$content = curl_exec($ch);
header("Content-type: text/plain");
echo $content;
That should echo exactly what cURL has received from the server...
NOTE: This is a re-post of https://stackoverflow.com/questions/8754844/can-not-get-images-using-curl
Furthermore
If you want to fetch the actual image inside a <img src=""> tag then you need to pin-point the IMG tag in the result HTML response using preg_match, and do a seperate cURL request to the IMG SRC

How to analyze HTML Page using PHP?

Hi I want to analyze HTML page by following example.
I can put url page to textfield then press enter.
I get some text from HTML page such as title, h1, div id="do" or so on.
How I can do it by using PHP?
Thanks!
With file_get_contents() or the like and an HTML parser.
You want to use PHP's curl functions, here's a quick tutorial.
Use file_get_contents or cURL, then use the explode functions to get data from the tags if using file_get_contents OR use "regex" for the particular html tag for getting the data

Categories