How to Read a Whole file at once in PHP?

How to Read a Whole file at once?

file_get_contents( ) Function is used to read entire file into a string. This function is the preferred way to read the contents of a file into a string. Because it will use memory mapping techniques, if this is supported by the server, to enhance performance. This function is binary-safe (meaning that both binary data, like images, and character data can be written with this function). The function returns the read data or FALSE on failure.

What is file_get_contents() Function?

The file_get_contents( ) function in PHP is a built-in function for reading a file and converting it to a string. The function makes advantage of server-supported memory mapping methods, which improves speed and makes it a favored method of reading file data.

Syntax:

file_get_contents($path, $include_path, $context, 
                              $start, $max_length)

Parameters:

The PHP method file_get_contents() takes one necessary parameter and four optional options.

  • $path: It provides the location of the file or directory to be examined.
  • $include_path: It’s an optional parameter that searches the include path (in php.ini) for a file even if it’s set to 1.
  • $context: It is an optional argument for specifying a custom context.
  • $start: It’s an optional argument that specifies where to start reading from in the file.
  • $max_length: It’s an optional parameter that specifies how many bytes should be read.

Return Value:

On success, it returns the read data; on failure, it returns FALSE.

Errors And Exception

  • If you wish to open a file that contains special characters like spaces, you must first encode it with urlencode ().
  • The file_get_contents() method produces a non-Boolean result that evaluates to FALSE, but it can also return a Boolean value.
  • If filename cannot be found, maxlength is less than zero, or searching to the given offset in the stream fails, an E WARNING level error is produced.

Let’s take examples to explain how file_get_contents() works:-

Input:  file_get_contents('https://www.scmgalaxy.com/');
Output: A computer science portal for scmgalaxy

Input:  file_get_contents('test.txt', FALSE, NULL, 0, 14);
Output: A computer science portal for scmgalaxy


Example 1:-

Output: 

A computer science portal for scmgalaxy

Example 2:-

Output:-

A computer science portal for scmgalaxy

Tagged : / / / / / / /

How to create a Responsive Navigation Bar with HTML CSS and Javascript?

In this tutorial, I am using HTMO, CSS, and Javascript and create a Responsive Navigation Bar. So, first create page with “.html” extension and write code as below-

And Below CSS code which is using in this navigation bar-

After that complete a Responsive Navigation bar as below –

When using a cursor on navbar link then uses “:hover” css function
In this Mobile showing as view responsive with “toggle” fa fa icon
When Click “toggle” fa fa-icon then show this type of navigation bar.
Tagged : / / / /

How does the JavaScript Promise work?

Promise

A Promise is an object representing the eventual completion or failure of an asynchronous operation. A JavaScript Promise object contains both the producing code and calls to the consuming code. It can be used to deal with Asynchronous operations in JavaScript.

Promise State:-

Pending – Initial State, Not yet Fulfilled or Rejected
Fulfilled/Resolved – Promise Completed
Rejected – Promise Failed

How Promise works

  • A pending promise can either be Resolved with a value or Rejected with a reason (error).
  • When either of these options happens, the associated handlers queued up by a promise’s then method are called.
  • A promise is said to be settled if it is either Resolved or Rejected, but not Pending.

Creating Promise

Promise () – A Promise object is created using the new keyword and its constructor. This constructor takes a function, called the “executor function”, as its parameter. This function should take two functions as parameters. The first of these functions (resolve) is called when the asynchronous task completes successfully and returns the results of the task as a value. The second (reject) is called when the task fails and returns the reason for failure, which is typically an error object.

Syntax:- Promise (executor)

A JavaScript Promise object contains both the producing code and calls to the consuming code.

Function Returning a Promise

then( ) Method

The then() method returns a Promise. It takes up to two arguments: callback functions for the success and failure cases of the Promise. As then the method returns a Promise so we can do method chaining.

Syntax:- then(onResolved, onRejected)

onResolved – A Function called if the Promise is fulfilled. This function has one argument, the fulfillment value.

onRejected – A Function called if the Promise is rejected. This function has one argument, the rejection reason.

Promise

Chaining

The then method returns a Promise which allows for method chaining. If the function passed as a handler to then returns a Promise, an equivalent Promise will be exposed to the subsequent then in the method chain.

catch () Method

The catch() method returns a Promise and deals with rejected cases only. It behaves the same as calling then(undefined, onRejected). In fact, calling catch(onRejected) internally calls then(undefined, onRejected).

The catch method is used for error handling in promise composition. Since it returns a Promise, it can be chained in the same way as its sister method, then()

Syntax:- catch(callback)

Where the callback is a function called when the Promise is rejected. This function has one argument error – The rejection error.

catch () Method

finally () Method

The finally() method returns a Promise. When the promise is settled, i.e either fulfilled or rejected, the specified callback function is executed. This provides a way for code to be run whether the promise was fulfilled successfully or rejected once the Promise has been dealt with.

This helps to avoid duplicating code in both the promise’s then() and catch() handlers.

Syntax:- finally(callback)

finally () Method

Chaining

Tagged : / / / /

Tutorial for Closing File in PHP

Closing file in php is all related to fclose( ) Function. With the help of this code we can run closing function in php.

What is fclose( ) Function in php?

In PHP, the fclose() method is used to close a file referenced by an open file pointer. If the method fclose() is successful, it returns true; otherwise, it returns false. It accepts the file that needs to be closed as an input and closes it.

Syntax:

bool fclose( $file )

Parameters:

The $file argument is the only one accepted by PHP’s fclose() function. The file that has to be closed is specified by this argument.

Return Value:

If it succeeds, it returns true; if it fails, it returns false.

Errors And Exception:

  • If you want to read the contents of a file that was written using the fwrite() function, you must first shut it with the fclose() function.
  • For remote files, PHP’s fclose() method does not work. It only works with files that the server’s filesystem can access.

Let’s take examples to explain this function:

Input : $check = fopen("gfg.txt", "r");
        fclose($check);
Output : true

Input: $check = fopen("singleline.txt", "r");
       $seq = fgets($check);
       while(! feof($check))
       {
         echo $seq ;
         $seq = fgets($check);
       }
       fclose($check);
Output:true

Example 1:-

Output:

Example 2:- The file test.txt in the software below includes just one line: “This file contains only one line.”

Output:

Tagged : / / / / / / / / / / / /

How does the Import and Export module work in JavaScript?

What is Module

In JavaScript, a Module is a JavaScript file where we write codes. The object is a module that is not available for use unless the module file exports them.

Exporting Module

export – The export statement is used when creating JavaScript modules to export functions, objects, or primitive values from the module so they can be used by other programs with the import statement.

There are two different types of export – named and default. You can have multiple named exports per module but only one default export.

Default Export

You can have only one default export per module. A default export can be imported with any name.

mobile.js

Named Export

You can have multiple named exports per module. Named exports are useful to export several values. During the import, it is mandatory to use the same name of the corresponding object.

mobile.js

Named Export

You can have multiple named exports per module. Named exports are useful to export several values. During the import, it is mandatory to use the same name of the corresponding object.

mobile.js

Importing Module

import –  The static import statement is used to import bindings that are exported by another module. Imported modules are in strict mode whether you declare them as such or not.

Importing Defaults

You can have only one default export per module. A default export can be imported with any name.

mobile.js

app.js

Importing Named

You can have multiple named exports per module. Named exports are useful to export several values. During the import, it is mandatory to use the same name of the corresponding object.

mobile.js

app.js

Importing All

mobile.js

app.js

Importing Default and Named

mobile.js

app.js

Tagged : / / / /

How to Become an Android App Developer?

Android is an open-source operating system, based on the Linux kernel and used in mobile devices like smartphones, tablets, etc. Various applications like games, music player, camera, etc. are built for these smartphones for running on Android. Google Play Store features quite 3.3 million apps.

You must admit that learning Android app development isn’t easy as it look. For the non-programmer there are several steps in the process, and even experienced programmers have quite a bit to learn when adopting Android. If you’re interested in developing new and innovative applications for the world’s #1 mobile platform – here are my six steps to becoming an Android app developer.

Now the questions arise are, Why Android? How to start? Where to start? And many more Question like this. So in this particular blog we will discuss in all this topics and I will try best to answer them all. Let’s start-

Who is an Android App Developer?

An Android App Developer is a Software Developer expertise in designing applications for the Android for mobile platform. This is the only competitor to Apple’s app store. Their job revolves around creating the apps we use on our smartphones and tablets. It is a skilled, entry-level position.

According to the recent studies, demand for Software Developers, which includes Android Developers, is expected to rise a whopping 21 percent through 2024. As an Android developer, you need to be very clear with your job posting and your responsibilities. So, here are some key roles and responsibilities of an Android Developer, that define who can be a successful developer.

These roles and responsibilities define who can be a successful developer.

There are several of specific tasks that an Android app Developer execute to develop Android applications. There are some of the following duties of Android app Developer-

Design and Build Advanced Applications for the Android Platform

In this an Android Developer dedicates most of their time. This development includes of using C / C++, JavaScript and a few other tools to write program code. It requires extreme attention, because one mistyped line of code can spoil the whole program.

Collaborate with Cross-Functional Teams to Define, Design and Ship New Features

An Android App Developer works with Product Development, User Experience and several other departments to define and design new features that users actually want.

Troubleshoot and Fix Bugs in New and as well as on Existing Applications

An Android App Developer’s job isn’t done after an application is completed. In fact they are also responsible for troubleshooting bugs that arise when the app is shipped to users in near future.

Continuously Discover, Evaluate and Implement New Development Tools

Android App Developers have to be up to date by latest trends in mobile application. They have to discover new tools as they hit the market. This requires the ability to adapt to an ever-changing environment.

Work With Outside Data Sources and APIs

An Android App developer spends so much amount of time working with outside data sources and APIs that provided.

How to become an Android App Developer?

Android App Developers can follow an easy pathway to become a successful Android App Developer as they already have an idea about how the applications work.  However, If you are someone, want to start your journey towards becoming an Android App Developer and really gain an advantage in the job market, then start working on these advanced skills many employers prefer in their Android App Developers career-

  • Should have strong knowledge of Android SDK and different versions of Android.
  • Proficient in programming languages like Java/Kotlin.
  • Strong knowledge of Android UI design principles, patterns, and best practices.
  • Decent knowledge with SQL.
  • Proficient understanding of code versioning tools, such as Git.
  • Familiarity with RESTful APIs that connects Android applications to back-end services.
  • Experience working with offline storage, threading, and performance tuning.
  • Possess the ability to design applications around UI such as touch.
  • Ability to understand business requirements and translate them into technical requirements.
  • Familiarity with cloud message APIs and push notifications.
  • Understanding of Google’s Android design principles and interface guidelines.
  • Familiarity with continuous integration.

At last, mastering these skills will definitely help you grow as a successful Android App Developer. And also do note that Android is one such domain where jobs are never out of stock. So start now to be an amazing developer.

Job roles

  • Mobile App Developer
  • Android Engineer
  • Mobile Architect
  • Embedded Software Engineer – Mobile
  • Lead Software Engineer- Mobile
  • Android Developer
  • Android Engineer
  • Mobile Developer

Why you should choose Android App Developer as a Career?

There are so many reasons why you should go for Android Development. Some notable ones among them are listed below:

Salary

According to the recent studies, the national avg. salary for Software Developers, which includes Android Developers, is $109,300. Those in the bottom 10 percent make less than $57,300, while those in the top 10 percent make more than $183,700. The three states with the highest median salary for Android Developers are California at $128,700, Washington at $123,400 and Massachusetts at $113,600.

Android is an evolving platform

Applications that are created are gaining lot of popularity and are rated top on the Google play store. With the time, Google keeps changing certain functionalities and releasing the new versions. So, you get updates yourself on a regular basis to improvised features that are added to your application. This is also a challenging task to develop, something that can catch the eye of any user.

Easy to learn

The developers out there will definitely feel that the time invested in learning how to develop an Android application is comparatively less than what they invest in other technologies. Have the knowledge of Java and scripting languages like Perl, PHP, and the job is done.

Conclusion

By learning Android development in 2021, you open up for many career opportunities such as freelancing, becoming an indie developer, or working for high profile companies like Google, Amazon, Facebook and more. The demand for native Android developers is still very high, and learning Android development has never been easier thanks to increases in online learning materials. Choosing Android App Developer as Career is a good option in 2021, If you want to learn or want to become an Android App Developer than I would like to suggest you DevOpsscool, One of the best option for this course, provide you best learning experience with in-hand practices, Experts are there to solve your query. Don’t wait for the right time to come, Start your learning today.

I Hope this blog is helpful for you and enough knowledge of Android App Developer.

Thank you!!

Tagged : / / / / / /

Adding Bootstrap 4.4.0 CDN to HTML

For css:

For js:

JS is only necessary if you plan on using one or all of the following components: Alerts, Buttons, Carousel, Collapse, Dropdowns, Modals, Navbar, Tooltips, and Scrollspy.

Css & js

This code will help you lot

Tagged : / / / / / / / /

Bootstrap 4.4.0

Bootstrap 4 is the newest version of Bootstrap, which is the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites. Bootstrap 4 is completely free to download and use! Bootstrap 4 with new components, a faster stylesheet, and more responsiveness.

What is Bootstrap?

  • Bootstrap is the most popular HTML, CSS, and JavaScript framework for developing a responsive and mobile-friendly website.
  • It is a free font-end framework (HTML and CSS) for faster and easier web development.
  • Bootstrap is famous for being development with components that have the ability to follow the property of responsive designs.
  • It gives you the ability to easily create responsive designs.

Advantage and Disadvantage

Advantages

  • Works in all modern browsers(IE9+,chrome,safari,mozilla e.t.c)
  • Rapid development
  • Fully and easily customizable
  • Comes with jquery plugins.

Disadvantages

  • My new website looks just like everyone else’s !
  • No backward compatibility in between versions
  • Using Bootstrap for existing websites is a tedious task.
  • You will likely not be earning any money for quite a while.

Why Use Bootstrap?

  • Easy to use : Anybody with just basic knowledge of HTML and CSS can start using Bootstrap.
  • Responsive features : Bootstrap’s responsive CSS adjusts to phones, tablets, and desktops.
  • Mobile-first approach : In Bootstrap, mobile-first styles are part of the core framework.
  • Browser compatibility : Bootstrap 4 is compatible with all modern browsers (Chrome, Firefox, Internet Explorer 10+, Edge, Safari, and Opera).
Tagged : / / / / / / /