I am trying to convert my html page to word doc file. But all php script converts to table based word document and my requirement is that the converted document should be in text based file means a doc file.
I'm a little confused at what you're asking. So I will make a few assumptions and hope I'm answering your question.
You can explicitly state the headers in PHP such that the document you're generating should be viewed as a rich text document with the following line:
header("Content-type: text/richtext");
However, this will, in some browsers, prompt you to download the generated file to your computer, if instead you want to have a rich text file displayed right in your browser you can actually use the .rtf extensions on the PHP file to be run by PHP, but you have to specifically tell Apache (assuming you're using Apache) you want it to interpret RTF files. You can do this by editing your Apache config file and adding RTF like so:
AddType application/x-httpd-php .php4 .php .php3 .phtml .rtf
There are online tools that can help you "generate" Word Document files "on the fly" dynamically/programatically using special markup language. Google will help you find the various libraries. This one in particular, which I do not believe is free, has been used by a friend of mine in the past:
rtf.generator
Hope this helps!
Related
If I add some php code to a .html or .htm file in PhpStorm, the code style for that bit of php code is NOT the same as in .php file.
For instance, here is the same code in two different file formats:
.php
.htm
How can I get the php code segment inside of the .htm to look like it does in a .php file?
UPDATE
The reason I want php code styling within an htm file is because I am using October CMS. October CMS uses a .htm file extension which is divided into three section. One of those section is for php code. What I want to know is how can I get the php content code which resides in the htm file to use my php code styles within PhpStorm.
In order for PhpStorm to recognize and highlight PHP code in any file such file MUST be associated with "PHP File" file type and have PHP icon next to file name.
By default .htm/.html files are associated with "HTML Files" file type.
Few possible solutions:
Change extension of existing file to be .php
Use .phtml file extension -- which is commonly used extension for such cases (in general denotes that this file is a "template" -- a HTML file mixed with PHP instructions)
Associate .htm (or whatever else extension you want) with "PHP File" file type.
For that: Settings/Preferences | Editor | File Types -- find "PHP File" and add appropriate pattern (e.g. *.htm). IDE will ask if you want to remove such pattern from existing/default "HTML File" to this "PHP File".
Possible downside: some HTML inspections may not be triggered (relaxed) in PHP file.
NOTE: Such association is IDE-wide and affects ALL projects.
The best/most neutral solution overall is #2 -- use dedicated file extension for such files (*.phtml is a most commonly used).
PHP needs to be in a .php file. It's changing colour because your text editor is telling you that the browser will treat it as text if it's in a .html file.
Rename it to .php and you'll be fine.
I have worked in a PHP project with .phtml files, that means the view contains PHP code and the same goes with a ASP.NET project with the respective .cshtml files that contain C# code. So far so good. However, I never wondered if those extensions, also serve some other purposes. Can someone shed some light and explain the use of those extensions?
For example, in a PHP app with some framework, if some backend code is needed in the view, that code would be in PHP, so why we need to specify a .phtml extension instead of just .html, in our view files?
So technically, we can make any file extension parse in any language we want. For example, if I wanted all .html files to be able to render using PHP I would use something like the following in my httpd.conf (or htaccess if I had the permissions).
AddType application/x-httpd-php .html .htm
In regards to the .phtml and .cshtml it's most likely that these file extensions are already mapped to render using the appropriate language/framework, meaning it's already done for you and you don't have to manually do it yourself (just as I don't have to map .php files to render using the PHP framework).
I've noticed that the .html and .php file extensions can be interchanged without apparent effect. Why would I want to use one file extension over the other?
A page ending in .php can include both HTML and/or PHP code (also javascript, css, etc inside their appropriate tags). Note that it is perfectly fine for a page without any PHP code to still have the .php extension.
However, if your page does include PHP code, the filename extension must be .php. Try it - on most web servers this won't work:
FILENAME: test.html
<?php
echo 'Hello there';
The above page will be blank. But if you rename it to test.php, you will see the hello message.
Filename extensions are also an indicator to yourself, or other programmers, as to what type of code the file contains. It is clear at a glance that a file ending in .HTML does not contain any PHP code (especially since any PHP code contained within won't work unless the webserver config is specifically modified to allow it).
One Final Note: these days it is pleasing to have web pages that do not end with an extension at all. Of course, you cannot leave off the extension of a .php or .html page... but you can hide the extension (including the period), making the page look like it was served by Flask or React or etc. You do this via a .htaccess file (yes, exactly like that, dot and all) that sits in the root folder of your website (same folder as the index.php or index.html). See:
https://code-boxx.com/hide-php-extension-url-htaccess/
https://tecadmin.net/remove-file-extension-from-url-using-htaccess/
Here is an interesting tool to help build .htaccess files
Use .html as a default.
If your page is running phpscripts then use .php
So, if you are communicating with server, use .php
.html and .php are file extensions but the more important question is how they are run.
A .php file can run server side script and take in mysql queries and open a connection etc...all of which are server-side functions.
Html is static and only displays static content but that has now changed with HTML 5.I suggest you do a simple search to learn more about php and html and their fundamental differences.
Files are handled depending on config and context. Shebangs, default programs, Apache Handler's, HTTP Headers, etc. describe handling files in various scenarios.
Executing Files In Terminal
The .php extension indicates that it is a PHP script, but the extension isn't necessary.
example-file.php
<?php
echo 'Hello World';
The script can be executed with PHP, which is clear because of the extension:
> php example-file.php
example2-file
#!/usr/bin/env php
<?php
echo 'Hello World';
With a shebang on the first line the OS can try to use the correct interpreter for the user so that the command is simplified to:
> ./example2-file
Some of the implementation details are hidden from the user by removing the file extension.
Packages often retain the extension on the source, but drop the extension during installation.
Default Programs
An extension can indicate to an OS which program to use to open a file.
Files ending in .php on my computer open in an IDE for editing whereas .html files open in a browser.
Servers and Headers
Web servers can send a file with any extension and content-type since many files don't actually exist, but are dynamically generated.
PHP web servers will serve .php files with the text/html content-type because the PHP is interpreted into text. Servers configured to return the raw PHP file as another content-type, i.e. servers not configured for PHP, will cause the web browser to download the source file rather than view the rendered file as HTML.
Since the resulting file after execution is HTML and web servers can dictate the extension, some developers decide to use .html in the URL and have them correlate to .php files to execute and return. Or the URL can not use an extension at all.
Using distinct extensions has the same purpose in PHP as it does in any language -- it makes it easier to determine the type of file you're using.
You may want to ease your web server's burden by having .html files not ran through the PHP processor, or you may want to have your PHP files not labeled .php to help hide what technology you're using server-side.
When I am starting to build a site that is going to require both HTML and PHP, should I be making a .html file with PHP in it (as in the file would be, say, index.html but within it there would be various tags)? Or, should I be making the files .php files and simply include HTML within it (as in the file would be, again say, index.php and it would start as PHP and I would simply intertwine HTML)?
TL;DR: Should I be weaving HTML into .php files or weaving PHP into .html files?
It should be a PHP file with HTML "weaved" into it. By default if your server sees an HTML file it does not think it needs to process scripts on the page and will render it. If it sees a PHP extension, it knows it needs to run through the PHP Processor.
You can modify your htaccess to allow HTML to be rendered through the processor, but there really is no need for you to be modding that, especially if you are a beginner.
You use PHP files with HTML in it
You should "weave" html into php files That way you know for sure your code will work on any server, and not just on servers that renders html files as php.
You need to specify in your .htaccess file to be able to parse PHP inside of a .html file. The easier way to go is just to make everything .php.
Inevitably, when you get more comfortable with PHP, you'll learn that you'll always have a little PHP in the file (like a require or something), so best to plan for that.
If you are new to PHP, I would recommend creating files with the .php extension, as the .php file can be executed by default. Depending on your server configuration, you may have to add some .htaccess directives to allow php code to run in an .html file.
If you like .html extensions, you can use .phtml files for templating your system, but only for the files that containing html code. And I prefer to use .php files that containing only php code like classes etc (this is what Zend or similar libs do).
How do you configure movable type to allow php in html files? I have seen places that people do the php tag in a html file and the server knows how to interpret the php in the html file. Is there a way to do this for Movable Type?
Have a read here: http://php.about.com/od/advancedphp/p/html_php.htm
Movable Type can output anything. If you name a template with .php and then include php in your template, when the rendered file is browsed, it'll be interpreted as php.
Same goes for asp, jsp, css, html... as long as your web server can serve it, Movable Type can output it.
Movable Type would publish the content exactly as you're writing it inside the movable type admin, in other words you don't need to do anything to movable type to interpret the php coding that you might place inside your pages.
If you have movable type configured to publishes pages with the .php extension, then the server would correctly implement your php coding.
But since you are having movable type configured to publish pages with the .html extension, those pages are interpreted by the server as HTML pages. What you need to do is to configure your server so that it will interpret your .html pages as PHP.
This setting could vary from a server to another, but you would usually add the following to your .htaccess file:
AddHandler php5-script .html
This change could also be done from inside Cpanel, under:
Advanced -> Apache Handlers
Check your site pages after implementing such a change and make sure that they work properly because it could generate errors and you may like to revert back the setting until you find the suitable one for your server environment.
You can use php in html codes,but the file need to be in PHP,you can use HTML also,it doesn't matter that is PHP.For example this code is in HTML and also have PHP:
<html>
<head></head>
<body class="page_bg">
Hello, today is
<?php
echo "Hello world";
?>
</body>
</html>
To conclude,the file must be in PHP.This don't mean a problem where you work in HTML,but for use PHP you need to do this.
No, not really.
You can put HTML in a PHP file. This works because the PHP interpreter recognizes the PHP parts (and processes them), and also recognizes the HTML parts (and passes them on directly).
With Movable Type, you typically don't have a PHP interpreter.
There's been discussion about porting Movable Type from Perl to PHP:
http://forums.movabletype.org/2008/09/full-php-movable-type-platform.html