PhpStorm Started Recognising .php Extension as Plain Text - php

Everything was working fine until now, and all the files I was creating as .php was being converted to .php file with detecting, coloring and auto-correcting open. I used to create files as created I User.php instead of `User.
PhpStorm randomly started recognising .php extension as plain text and without extension as php file.
However, now something happened and it is shown as (see Profile is not detected asphp file):
and is shown as a plain text file:
When I remove the .php, it gets detected:
And then it gets detected as PHP file , but then it doesn't show the extension in the Finder

Found my answer.. Settings > File Types > Check under PHP and Text and delete Profile

Related

Why does my styling completely break when I change .html file extension to .php

I need to include some php code on my contact form page so I tried changing the file extension from .html to .php and either my css page no longer connects or the html isn't even displaying properly. When open in a web browser only the lines of code (of the new php doc) as typed appear. Before changing the extension everything is styled and layed-out correctly, only changing the extension completely breaks it. Why is this? and how do I fix it?
Create a new php file and copy the content from that page to the new file and see if it works
fix: I had a firewall blocking my localhost server when I tried opening the website folder. I just needed to whitelist the port. Thanks for the suggestions !

PHP Code Style in .htm File in PhpStorm

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.

Why does .htaccess automatically changes to .htaccess.txt

I am trying to use mod_rewrite and appache to convert my dynamic URLs in to static ones. Therefore I created a .htaccess file in my root folder that is c:xampp/htdocs/unnamed. However whenever i try to rename my text document to .htaccess it automatically changes to .htaccess.txt. It appears only .htaccess in the folder but when i look in the details in the properties menue it is actually .htaccess.txt. Does anyone know how do i change it to just .htaccess
That is because on windows it thinks .htaccess is the name of the file. It considers it to be text. Linux it works differently. It doesn't depend on extensions in Linux.
In order for it to work you just rename the file and remove .txt from it. Then it should work how you like it.
Open the file your created in a text editor, just use Notepad.
Choose "Save as.." and select "All types (.)" next to file type.
Then type .htaccess and click on save.
FYI: I would also turn on showing file extensions if you don't already have that on so you can see what extensions your files have by looking at them in the folder.
http://windows.microsoft.com/en-us/windows/show-hide-file-name-extensions#show-hide-file-name-extensions=windows-7
This is because Windows default setting doesn't show the known file extension. You can change that option in the Folder option dialog.
But for easier, just open the command line and rename it by command:
ren .htaccess.txt .htaccess
Next time when saving a file, paying attention to the file extension, especially not to save source code as .txt file :).

When would I want to use .html, vs. .php, as a file extension?

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.

Problem installing phpimage for TinyMCE

Hay all, this is really bugging me.
I have downloaded phpimage from http://sourceforge.net/tracker/index.php?func=detail&aid=2844769&group_id=103281&atid=738747
I've decompressed the zip file and moved the "phpimage" folder into my "plugins" folder.
In my settings i've added "phpimage" to the "plugins" setting so it reads
plugins : " safari,pagebreak,style,layer,table,save,advhr,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,phpimage,",
And i've added the "phpimage" to the "theme_advanced_buttons1" settings, this looks like
theme_advanced_buttons1 : "phpimage,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,|,link,unlink,anchor",
when i load the editor up it reveals a blank textarea. If i remove the phpimage from the plugins setting the textarea appears as the TinyMCE.
Any ideas? Firebug isn't giving too much help.
Thing i discovered is if you load tinymce using the developer mode (tiny_mce_dev) the file editor_plugin_src.js is missing. You can correct this by copying the file editor_plugin.js and rename it to editor_plugin_src.js.
This comment of KOPFteam at SF helped me make it work at last. It was the langauge file!!
My langugage setting is "de", so after creating a file under langs called de.js it worked like a charm and the editor was back. What is your language setting?. I suggest you name it according to this setting. Here KOPFteam's comment:
It's up and running in German!
It took me a few hours to sort out a
few problems:
1) I uploaded the phpimage folder into
the tiny_mce/plugins folder, created
an image upload folder, entered
"phpimage" twice into my tinyMCE.init
and - no tinyMCE anymore. Pure HTML.
What happened? I checked the Webserver
ErrorLog where a "file
...../phpimage/lang/de.js missing"
shows. I have no idea why it is
looking for that file. I hadn't
changed /phpimage/config.php at that
point. So I duplicated the file
/phpimage/lang/en_dlg.js and renamed
it to de.js and suddenly tinyMCE is
back! And the phpimage button works -
with the dialog in English. 2) Next I
tried to upload an image. I got an
alert that an folder cannot be created
(I forgot the exact text). I solved
that by editing /phpimage/config.php
by adding a fifth "/.." to the
definition of $_cur_dir. After that
uploading of images worked. 3) Because
I found it on the authors website, I
uploaded the file
/phpimage/classes/lang/class.upload.lang.de_DE.php
and than changed the $language
parameter in /phpimage/config.php to
de_DE. After that I duplicated the
file /phpimage/lang/en_dlg.js again.
This time I renamed the copy to
de_dlg.js and translated the content
of that file to German. And after
that: a working dilaog with german
lables! BTW: German Umlauts can be
used by inserting the 4 digit unicode
value as in "Bild
einf\u00FCgen/bearbeiten" 4)After
uploading a modified file to my
webserver I had to quit and restart
Firefox. Simply reloading nstill
showed the old file.

Categories