Jump to content

arshedali0052

Member
  • Posts

    4
  • Joined

  • Last visited

Everything posted by arshedali0052

  1. Today, I’m going to talk about the important topic in PHP file system, file put content.

    Every single detail I will try to cover on this post and you will get some bonus tips on file put content.

     

    Let’s begin…
    File Put Content has used on PHP for Write data/text to a file. File Put Content is a default function in PHP, file_put_contents(), it’s comes with four parameters.

    The Syntax is: file_put_contents(file,data,mode,context);

    Example:

    <?php
    file_put_contents("example.txt","Hello World ! \nThe Data/Text Which one did you want to add on the file.");
    ?>

    The Output:

    file-put-content-output.png
     

    If you run this example, it will create a file to name, example.txt on where form you have run the file, if already have a file example.txt, then it rewrites the file and put the data on it. And “\n” means a new line/linebacker.

     

    File Put Content Parameters:

    File and data it’s a required parameter, you must have to declare this if you are using File Put Content file and mode & context both are optional.

    File:

    If you want to rewrite any existing file, add the file path with file name and extension, Same as if the fine does not exist on the path, it will create a new file.

    Data:

    Data means, which one did you want to add on the file, it can be string, data stream or array.

    Mode:

    it optional, it declares the way how to open/write data on the file, It’s work on three different fixed values:
    FILE_USE_INCLUDE_PATH
    FILE_APPEND
    LOCK_EX

    You can use one at a time or both of them at a time to use many you have to use “|”.
    if you don’t use any mode by default every time on rum, it will overwrite the file and add the data form began.

    FILE_APPEND will append the data form bottom of the file instead of to overwriting it, So your old data will exist and new data will be added form end of the old data.
    And LOCK_EX have used to prevent multiple users writing at the same time.
    And FILE_USE_INCLUDE_PATH have use for search files

    Context:

    It’s also optional, has used on the fileHandle to Specifies the context, you can also modify the behavior.
    Example:

    <?php
    file_put_contents("actors.txt","\nLeonardo DiCaprio \nTom Hanks \nBruce Lee", FILE_APPEND | LOCK_EX);
    ?>

    Or in Different way:

    <?php
    $file = 'actors.txt';
    $actors = "\nLeonardo DiCaprio \nTom Hanks \nBruce Lee";
    file_put_contents($file, $actors, FILE_APPEND | LOCK_EX);
    ?>

     

    “To get live examples, you can watch the video”

     

    Bonus concept with file put content:

    Let’s see some interesting thing with file put content & file get content to use both functions. File put content will get the create the file and file get content will get data to form any file link.
    Example:

    <?php
    file_put_contents("worpdress.zip", file_get_contents("https://wordpress.org/latest.zip"));
    ?>

    You need wordpress file on your server, So you have to downalod the file and then upload.
    You can simply add the WordPress files to use the example code.
    Not only WordPress also you can transfer any zip file from any server, Just flow the example and change the file get the content link and file name, You can also add any type of name.
    It’s cool, you can transfer a large amount of file in a few seconds.

     

    If you have any questions, you can comment, I will try to give solutions…

  2. Full installation & Config Sublime Text PHP linter Full Details With Screenshot

    Did you want to check PHP Error in your sublime text editor?
    And you already install php linter didn’t work?
    Don’t worry about this,
    In this post,
    I’m gonna show you details about PHP linter and PHP Error checking system in your sublime text editor.
    Don’t further delay, let’s get started
    In full process, I work in sublime text 3 if you have to install sublime text 2 so, please reinstall it to sublime text 3, it’s updated version and you get Some more extra features then sublime text 2.

    For this, you need to install tow sublime text plugin, one is “Sublimelinter” and another one is “PHP linter”.
    To get sublime text plugin installation features you need to install sublime “Installation – Package Control”. install the script, if you already have installed it’s ok for you.

    Now you need to install Sublimelinter, to install this open sublime text then go tools -> Command Palette or you can press “Ctr+Shift+p” to open command panel, Type “install package” in the search box then press enter to go Control Package.
    After this just type, Sublimelinter and press enter to install, wait few secs to complete the install process. then again do the same process to install PHP linter. after installing both plugins close sublime text. you have completed the first step.

    php-linter-instalation-screenshot-1.png

    Then now the second step to install PHP on your PC. Direct PHP installation processor is very difficult, so I will show another way to work PHP globally into your pc.
    if you work with PHP if have install localhost server on your PC right? in localhost software Already have PHP, we just make it work globally. In my pc, I have installed “XAMPP” if you have installed “WampServer” find the PHP folder in Wamp installation folder and then copay the link path. Same to XAMPP go to XAMPP installation folder then find PHP folder, open the folder and copy folder path.
    Then Right click my “My Computer” or “This PC” Then click properties, in left, you can see “Advanced system setting” click this, after clicking this you can see a pop window like the screenshot.

    php-linter-instalation-screenshot-2.png

    Click “Environment Variables” then form “User Variables for Perfect” box, find path select and click “New…” to add the path in Environment Variables.
    Then in popup add the path URL and variable name like the screenshot. after this click ok to all window.
    You are welcome you have successfully done all need task to work PHP linter. Now let’s check how it works, open sublime text and create a PHP file, and try to write a PHP code and do an error to check its work or not. if you get an error like the screenshot you successfully complete the process.

    php-linter-instalation-screenshot-3.png

    You can check out video to get more details

×
×
  • Create New...