I think I broke mi VS Code trying to join php and html syntax when I have a php file with html and php code.
The problem is that VS Code doesn't recognize .php files. The Select Language Mode shows as a 'Plain Text' and when I try to configure file association for '.php' doesn't appear.
I try a solution found "php.validate.excecutablePath" and I did not have results.
Finally I tried installing again VS Code after uninstall and delete all but doesn't work.
I don't know what to do.
I know it's very late lmao, but here's what I found; In order to make the setting re-appear, uninstall any extra php related extensions and restart vscode (you might also want to disable and re-enable php through searching "#builtin php" in extensions). That should bring the option back; then go and set up the path in the settings.json, and if you are a windows user add it to your environmental variables (specifically path).
Related
I have just installed fresh PhpStorm on Mac. I set my interpreter and so on. I can create .php files. But when I run it runs only JavaScript and there is no option to run php? How can I fix this?
Run 'filename.php (JavaScript...)'
Same with debug. How this can be fixed?
It seems you've configured PhpStorm to handle files with .php extension as JavaScript code rather than PHP.
Open the settings dialog (File/ Settings), head to Editor/ File Types and review the Recognized File Types section:
Remove *.php from JavaScript.
Make sure that PHP contains *.php.
Remove any other unwanted registered pattern, such as filename.php.
A while ago, I successfully configured Atom to beautify my PHP using php-cs-fixer, but now I need to go through the same process on another Mac and can't remember exactly how I did it.
As a front-end dev, I'm not a PHP expert, but I understand that the Atom plugin is merely the middleman facilitating the actual fixing using php-cs-fixer, which, by default, it doesn't have access to. Once I installed the fixer, I had to add its location to my PATH variable. The confusing part is that I don't have the fixer installed via Atom (checked ~/.atom/packages) nor Homebrew (confirmed with brew list), however, the file is present in /usr/local/bin. If I move it, Atom returns the original error, so it's definitely using this file:
See https://github.com/FriendsOfPHP/PHP-CS-Fixer for program installation instructions.
Your program is properly installed if running 'which php-cs-fixer' in your Terminal returns an absolute path to the executable. If this does not work then you have not installed the program correctly and so Atom Beautify will not find the program. Atom Beautify requires that the program be found in your PATH environment variable.
Note that this is not an Atom Beautify issue if beautification does not work and the above command also does not work: this is expected behaviour, since you have not properly installed your program. Please properly setup the program and search through existing Atom Beautify issues before creating a new issue. See https://github.com/Glavin001/atom-beautify/search?q=php-cs-fixer&type=Issues for related Issues and https://github.com/Glavin001/atom-beautify/tree/master/docs for documentation. If you are still unable to resolve this issue on your own then please create a new issue and ask for help.
Hide Stack Trace
Error: Could not find 'php-cs-fixer'. The program may not be installed.
at PHPCSFixer.module.exports.Beautifier.commandNotFoundError (/Users/ourcore/.atom/packages/atom-beautify/src/beautifiers/beautifier.coffee:204:14)
at /Users/ourcore/.atom/packages/atom-beautify/src/beautifiers/beautifier.coffee:304:22
at tryCatcher (/Users/ourcore/.atom/packages/atom-beautify/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/Users/ourcore/.atom/packages/atom-beautify/node_modules/bluebird/js/release/promise.js:510:31)
at Promise._settlePromise (/Users/ourcore/.atom/packages/atom-beautify/node_modules/bluebird/js/release/promise.js:567:18)
at Promise._settlePromise0 (/Users/ourcore/.atom/packages/atom-beautify/node_modules/bluebird/js/release/promise.js:612:10)
at Promise._settlePromises (/Users/ourcore/.atom/packages/atom-beautify/node_modules/bluebird/js/release/promise.js:687:18)
at Async._drainQueue (/Users/ourcore/.atom/packages/atom-beautify/node_modules/bluebird/js/release/async.js:138:16)
at Async._drainQueues (/Users/ourcore/.atom/packages/atom-beautify/node_modules/bluebird/js/release/async.js:148:10)
at Async.drainQueues (/Users/ourcore/.atom/packages/atom-beautify/node_modules/bluebird/js/release/async.js:17:14)
at process._tickCallback (internal/process/next_tick.js:103:7)
which php-cs-fixer returns /usr/local/bin/php-cs-fixer and my PATH variable currently contains /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/ourcore/.atom/packages/php-cs-fixer.
I guess my questions are, how is the fixer working if the PATH variable seems to be pointing to it in a different location, and how did it end up where it is? Does the location in my PATH matter at all, or does the Atom plugin know to look in /usr/local/bin? I just want to fully understand the entire process before repeating it.
EDIT: On further testing, I removed the Atom directory from my PATH and it didn't affect the plugin, so then I copied the file into the same directory onto the second Mac and it ran without issue, without needing to edit the PATH. Does the fixer file someone inform the OS?
Well first test "which php-cs-fixer" or "where php-cs-fixer" (depending on what os you're running) and if nothing is returned in the terminal then there actually is something wrong on the installation and the best thing to do is to manually install it.
Head to https://github.com/FriendsOfPHP/PHP-CS-Fixer and download it from there and follow the installation steps, after that it should all be good
i added php code in my cshtml view under asp.net mvc.
<body>
<?php echo"hello";?>
...
however it seems that vs does not understand that it's php and when I inspect element, the php code was automatically commented out.
<!--?php echo"hello";?-->
how can I solve this? I have already installed php tool extension in vs.
To run php script, you need to have .php files, or it won't be recognized.
To enable the script to be recognized as php without changing file suffix, add config files depending on the server you are using. (most likely Apache/IIS)
I need to assign a custom extension to be recognized as a twig file in netbeans ('blade.php' as 'twig' file and give me syntax highlighting and code completion appropriately). The problem with using the File association option (in Tools > Options > Miscellaneous > Files)
is that it won't let me add '.' in extension like blade.php, it works with single worded extensions like php, html, css etc.
Will be grateful if anybody can help me with this!
Workaround I figured out and seems to work (at least Netbeans 8.x+)
Go to Tools > Options > Miscellaneous > Files
Click New
Enter blade as the new extension (you can use anything here, but this seems the most natural)
Click OK
In Associate File Type (MIME) select TWIG (text/x-twig)
Click OK of the whole Options window
Close Netbeans
Open the Netbeans configuration folder - on Windows it's %AppData%\Netbeans\<version>\
Go to subfolder config\Services\MIMEResolver
Open user-defined-mime-resolver.xml
Find the <ext name="blade"/> entry (or whatever you entred above)
Change the blade to blade.php
Save and close the file
VoilĂ , higlighting should now work in Netbeans IDE :)
Modify the user-defined-mime-resolver.xml file so that it looks something like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE MIME-resolver PUBLIC "-//NetBeans//DTD MIME Resolver 1.1//EN" "http://www.netbeans.org/dtds/mime-resolver-1_1.dtd">
<MIME-resolver>
<file>
<ext name="php"/>
<name name=".blade" substring="true"/>
<resolver mime="text/x-twig"/>
</file>
<file>
<ext name="php"/>
<resolver mime="text/x-php5"/>
</file>
</MIME-resolver>
On Linux (Ubuntu), you can find this file at:
$HOME/.netbeans/8.2/config/Services/MIMEResolver/user-defined-mime-resolver.xml
On Windows, you can find the file at:
%AppData%\Netbeans\8.2\config\Services\MIMEResolver\user-defined-mime-resolver.xml
Basically, the first <file> block scans the filename of any PHP files to see if it contains the ".blade" substring. If so, the file is treated as a Twig file. If not, the second <file> block will treat the file as a normal PHP file.
You might need the "Twig Templates" NetBeans plugin in order to get proper highlighting:
Tools > Plugins > Available Plugins > Twig Templates
It's not perfect... Blade directives such as #include are still highlighted as plain text. However, I feel it is a marked improvement over PHP syntax highlighting.
The following sources were extremely helpful:
HOW TO: Declarative MIME Type Resolvers
DTD Grammar Documentation
David Benedeki's earlier answer to this question
A lot of people are developing on other systems, as I am on Centos 7, so this workaround almost worked.
For CentOS, and probably other systems as well, follow these steps, almost the same as above for Windows:
Open Netbeans. Go to Tools->Options->Miscellaneous and select tab Files.
In File Extension row, click New button. Enter crazywrongname as extension name (this is important for option 2)
Below that, under Associated File Type (MIME): choose the option TWIG (text/x-twig)
click Apply and then OK.
Close Netbeans
Option 1:
The following steps are for CentOS 7 and NetBeans 8.1, most probably for other systems as well, but if you can't find the file at that path, option 2 is below.
open Terminal and open the file /root/.netbeans/8.1/config/Services/MIMEResolver/user-defined-mime-resolver.xml in your favourite text editor, e.g. run command nano /root/.netbeans/8.1/config/Services/MIMEResolver/user-defined-mime-resolver.xml
find the parameter name "crazywrongname" in this file and change it to "blade.php"
save the file
open Netbeans and enjoy.
People from the future, you might try changing the Netbeans version in file path from option 1 to yours, like 14.3 or whatever is out in 2028.
Option 2:
If you can't find this file in the exact path as above, run this command to find it:
cd / && grep -rI --exclude-dir=proc --exclude-dir=sys crazywrongname *
This will start a search for the specific pattern on your whole system, starting at root. That's why we named the parameter crazywrongname - so it isn't found in any other file on the system, like blade would be. It will also exclude the folders that are not supposed to be accessed. If you don't exclude them, you will get errors and possibly hang your system. Also, some pink unicorns might die.
After you find the exact file path for your system, follow the remaining steps in option 1 for changing the parameter name.
Thank you, mysterious David Benedeki who disappeared from StackOverflow after answer which helped enormously :)
As I can see the problem is more NetBeans-centric, so I would also suggest you to file a bug report to the NetBeans community.
The NetBeans forums.
The NetBeans bug tracker.
Maybe in the future they can fix that issue. You may also link that question so they can see the user reactions.
For module development with custom *BladeDataObject file
#MIMEResolver.Registration(
resource = "BladeResolver.xml",
displayName = "#LBL_Blade_LOADER"
)
and in the same package create the BladeResolver.xml file with the content
<MIME-resolver>
<file>
<ext name="php"/>
<name name="blade" substring="true">
<resolver mime="text/x-blade"/>
</name>
</file>
</MIME-resolver>
I have an Apache server running PHP-5.3.0 for Windows. For the creation of pdf files, I need to activate the pre-bundled pdf library (referred here) in my php by editing the configuration file. How can I do this?
Or is there any other way to enable pdf creation?
Go to PHP's root directory > php.ini. Ctrl+F 'extension=php_pdflib.dll' and remove the semicolon (;) at the start of the line. Then restart Apache. If the semicolon isn't there, then it should already be activated. If there isn't any results from the Ctrl+F, it likely means you don't have it installed. You could try adding 'extension=php_pdflib.dll' (anywhere will do).
You can use a small file to test whether the library is loaded, just write in it:
<?php phpinfo();
Watch for php.ini in the output of this script, and add the following line to the file (you may need additional privileges to do that, right click your editor -> Run as Administrator):
extension=php_pdflib.dll
Restart apache, and check that pdf has been installed by checking the aforementioned phpinfo file.
Unless you're doing really advanced PDF stuff (and you need the non-free version of php-pdf for that), I can really recommend Prince XML. It converts XML and HTML into PDF and adds additional CSS properties, like page dimensions and numbers, PDF bookmarks and the like. Their documentation is better in demonstrating that than any of their marketing pages.
I solved it using TCPDF.. Its easy to handle. No need to edit php.ini.