I want to generate some static html files from a template and a large set of datas.
This "set" is an uploaded json (ie a blob that became a file) that I want to read in the generated page using javascript, so I was thinking about inserting it as a string into a <script> tag of the page (something like <script>json=MYJSON</script>, I don't know if it's the best way to achieve this ...).
Now the question is how to copy a file (template) and add/edit a part of it (a tag) in the new file...
It seems that the simplest way is to use copy and give GET parameters to the template wich get it with a php code that echoes the tag .. for example here with a 'name' GET parameter :
copy('http://localhost/site/template.php/?name=' . $name, '../public/new_file.html');
It works fine, but the problem is that I can't pass a large data using this method, so how to achieve this ?
Related
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.
I just made a Flash animation and put a dynamic URL inside an AS2 button...
then I exported the animation as HTML 5 using SWIFFY and it works fine if I call the URL from the original Swiffy file after changeing the extenssion to php, but the head section of my document is just too big, you know swiffy converts images to code ant the thing is just to big:
So I tried moving the swiffy code to an external js file and this is where the problem occurs, so than I tried putting the swiffi file inside an Iframe using href http://mysite.com/index?myvar=var and same result always get the php tags and $var on the url, made a two hour search in Google and haven't found an answer to my problem.
http://mysite.com/index?myvar=<?= $var ?>
Instead of:
http://mysite.com/index?myvar=var
the Swiffy code shows like this:
{"body":[{"value":"document.php?myvar=<?=$var;?>","type":305}
Yes I made a search and after two hours decided to post the question
any help is appreciated :)
The Swiffy FAQ here
https://www.google.com/doubleclick/studio/swiffy/faq.html
says (paraphrased):
You can pass a parameter to your Swiffy file in the URL like ?{variableName}=http://www.google.com, or by inserting the following code snippet in the Swiffy output, just before the call to stage.start():
or with JS like this right before you call stage.start();
stage.setFlashVars("{variableName}=http://www.google.com");
In your ActionScript code or Flash timeline, the would be assigned to the _root or _level0 object:
_root.{variableName} or _{variableName}
I don't have time to do a test case right now but that should work according to the documentation.
I want to store html that isn't to be rendered until needed either within a tag that can hold raw html code without rendering it on page load or store it within a php or jquery variable for later use. I then want to be able to insert the html into the DOM on button click and have it render.
I've tried storing it within an xmp tag as that can store html code with the < and > characters without using character codes for them, but when trying to insert it into the DOM, the updated source shows it had been copied but it wouldn't render on screen. Also tried storing it within a code tag, which worked on a desktop browser but not in mobile safari. Since this is a webapp mobile browser compatibility is important.
Anyone know of a good method of doing this?
Try <script> tags with a type of text/plain or text/html:
<script type="text/plain" id="example">
<div class="example">
<h2>Hello</h2>
<p>World</p>
</div>
</script>
$(".button").click(function () {
var html = $("#example").text();
$("#destination").html(html);
});
It depends on where do you want to generate the content in question. If it's easier for you setup to generate it on the server side, you can use css to hide those parts (like display:none) and just remove the css property or grab the nodes with javascript and put them elsewhere with something like this:
$('.target').html($('.hidden_node').html());
If you want to generate the content on the js side, you can build it as a long string and just shove it into the target, or you can use jquery's node generation syntax like:
$('<div />').attr({
class: 'test'
}).appendTo("body");
Or you can use one of the various javascript templating solutions like mustache or handlebars.
I was converting a HTML file to PDF using dompdf. I managed to get the desired result but a problem arose, the HTML file needs to be converted to PHP because it will receive data from a form (from another file)!
The dompdf in this case doesn't work and it not shows the result of what was written in the form.
I think what you search is a template Engine to replace values in a HTML file.
There are some Engines like Smarty, TWIG.
You can parse your HTML file and with the HTML return you can create your PDF file.
Perhaps its a bit oversized for your case but you could build your own short engine and parse your HTML file and replace your specified Tags with the form values.
You can create your html file automaticaly in temp. After request to your php file, your file generates automaticaly a .html file (in temp), then create your pdf from this file.
Let's say we have a .doc & .docx files. I want to use LiveDocx in PHP to load the files, read it's content and strip the text from inside it. Then save it to an HTML string.
Can this be done?
I've searched the documentation, and it seams that LiveDocx only loads .doc & .docx template files only!
You can save using external libraries and simply grab the text from the XML within the files:
http://www.webcheatsheet.com/PHP/reading_the_clean_text_from_docx_odt.php
I think you can find what you need in this example.
I might be wrong, but I think they call them "template" files because they act like a template but are still normal .doc/.docx documents. I suggest you simply try to run that example.
I think you can use TextControl that improves phpLiveDocx TextControl link
Using this you can also import pdf doc and docx
When you do document conversion on LiveDocX, you need to do a mailmerge and then retrieve the document. Even though you aren't inserting any new content, you need to do a mailmerge that replaces a dummy placeholder with dummy content.
So, the process I'd suggest is:
1) Set your source document as local template
2) Merge a dummy field with dummy content
3) Retrieve your document as HTML
4) Use a script server side to remove the html and leave only the content (Something like, remove everything between the HEAD tags, then strip_tags on the rest)
5) You should be left with your content as a simple string - I'm not sure it'll be too meaningful, but might be useful for building something like search indices.