We are developing a blog plug-in. we need to use this project Parser. how can we reference this project in the PHP file in an environment without composer, or directly install composer and this library in the PHP file? We are developing a blog plug-in. we need to use this project Parser. how can we reference this project in the PHP file in an environment without composer, or directly install composer and this library in the PHP file?
Reply content:
We are developing a blog plug-in. we need to use this project Parser. how can we reference this project in the PHP file in an environment without composer, or directly install composer and this library in the PHP file?
You can use the automatic loader, but it is better to use composer, which is convenient after all.
Https://github.com/WhichBrows...
function InstallComposer(){ file_put_contents(__DIR__ . '/composer-setup.php', file_get_contents('https://getcomposer.org/installer')); shell_exec('php composer-setup.php');}function InstallParser(){ shell_exec('php composer.phar require whichbrowser/parser');}
If you do not useComposer
: If there are few files,require
If many files are involved, the usage specification of the library namespace isPsr4
OrPsr0
, Writeautoload
Method to automatically introduce files. For more information, seeComposer
OfClassLoader
.
If you useComposer
, Directly writecomposer.json
, Put the required Libraryrequire
.
# Composer. json "require": {"php": "> = 5.3.3", "godtail/db ": "dev-master" # Example} # then composer install '# introduce the autoload file require '.. /vendor/autoload. php ';
Of course, Composer is recommended for componentization, which is more convenient.
Install parser first
And then in the file
require 'vendor/autoload.php';
In this way, you can