Multiple Index Variables in PHP foreach Loop

AmitDiwan
Updated on 09-Apr-2020 11:01:08

5K+ Views

The ‘foreach’ loop can be used to multiple index variables of two arrays. This has been shown below −Example Live DemoOutputThis will produce the following output −aB12 PQ34 cd90 pm49Note − If there are more than 2 arrays, nested ‘foreach’ loops can be used.Here, 2 arrays have been declared and they are being traversed using the ‘foreach’ loop. The result is that the respective index of every array is matched and the data at those indices are displayed one next to the other.

Strip Punctuation with PHP

AmitDiwan
Updated on 09-Apr-2020 10:59:31

1K+ Views

The ‘preg_replace’ function can be used to match the characters in the string and remove the unnecessary characters.To keep letters and numbers −Example Live DemoOutputThis will produce the following output −Hello my name is Bobby I am 8 yearsTo keep letters only −Example Live DemoOutputThis will produce the following output −Hello my name is Bobby I am yearsTo keep letters, numbers and underscoreExampleOutputThis will produce the following output −Hello my name is Bobby I am 8 years

Detect Base64 Encoding in PHP

AmitDiwan
Updated on 09-Apr-2020 10:49:18

731 Views

To detect base64 encoding in PHP, the code is as follows −Example Live Demo

Remove All Empty Values When Exploding a String in PHP

AmitDiwan
Updated on 09-Apr-2020 10:48:09

1K+ Views

The array_filter() or PREG_SPLIT_NO_EMPTY option on preg_split() can be used to remove empty values from a string when it is exploded −Example Live Demo

PHP fopen to Create Folders

AmitDiwan
Updated on 09-Apr-2020 10:44:09

2K+ Views

The fopen can’t be used to create directories. This is because fopen function doesn't create or open folders, it only works with files.Before using the fopen function, one should check with is_dir first if it exists, if not create it using the mkdir function −$filename = '/path/to /file.txt'; $dirname = dirname($filename); if (!is_dir($dirname)) {    mkdir($dirname, 0755, true); }The above code creates a path to the file named ‘filename’. The directory of the ‘filename’ is obtained using the ‘dirname’ function. Next, this directory is checked for the existence using the ‘is_dir’ function. If the directory already exists, no operation takes ... Read More

Import CSV File in PHP

AmitDiwan
Updated on 09-Apr-2020 10:40:30

1K+ Views

The below code can be used to import CSV file in PHP −The file will display the contents of the csv file are displayed on the screen.In the above code, beginning from row 1 (since row 0 would usually contain headers/column names), the csv file is opened in read mode and the fgetcsv function is called to read in 1000 rows of data present in the csv file.The number of columns in every row is displayed along with the contents of it.

Display Different List Commands in JShell in Java 9

raja
Updated on 09-Apr-2020 09:28:48

413 Views

JShell has introduced in Java 9 and is a command-line tool that allows us to enter simple statements, expressions, methods, and classes without a main () method.When we can enter code in JShell, the code has assigned a unique ID. This ID starts at 1 and has incremented for each command entered in JShell. The same can be true for libraries loaded at startup. For each of these imports, a unique ID has been assigned. It starts with $1 and is incremented for each code loaded ($2, $3 and etc). There is an internal command to list all code loaded, and ... Read More

Declare OpenCV Mat Object Using Java

Maruthi Krishna
Updated on 09-Apr-2020 09:24:23

825 Views

In OpenCV Mat class represents a matrix object which is used to store images. You can also declare a Mat object manually −Load the OpenCV native library − While writing Java code using OpenCV library, the first step you need to do is to load the native library of OpenCV using the loadLibrary().Instantiate the Mat class − Instantiate the Mat class using any of the functions mentioned in this chapter earlier.Fill the matrix using the methods − You can retrieve particular rows/columns of a matrix by passing index values to the methods row()/col().you can set values to these using any of ... Read More

Explain the Mat Class in Java OpenCV Library

Maruthi Krishna
Updated on 09-Apr-2020 09:22:09

2K+ Views

In OpenCV, images are stored in Using Mat object. It is nothing but an n-dimensional array and is used to store image data of grayscale or color images, voxel volumes, vector fields, point clouds, tensors, histograms, etc.If you try to read an image using the OpenCV library it will be read to a Mat object.Mat matrix = Imgcodecs.imread(filePath);You can instantiate this class manually using one of the following constructors −Mat() − A no-arg constructor, used to create an empty matrix and pass this to other OpenCV methods.Mat(int rows, int cols, int type) − This constructor accepts three parameters of integer ... Read More

Create Custom Color Maps in Java Using OpenCV

Maruthi Krishna
Updated on 09-Apr-2020 09:20:38

470 Views

The applyColorMap() method of the Imgproc class applies specified color map to the given image. This method accepts three parameters −Two Mat objects representing the source and destination images.An integer variable representing the type of the color map to be applied.You can pass any of the following as color map value to this method.COLORMAP_AUTUMN, COLORMAP_BONE, COLORMAP_COOL, COLORMAP_HOT, COLORMAP_HSV, COLORMAP_JET, COLORMAP_OCEAN , COLORMAP_PARULA, COLORMAP_PINK, COLORMAP_RAINBOW, COLORMAP_SPRING, COLORMAP_SUMMER, COLORMAP_WINTER.Exampleimport org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.imgcodecs.Imgcodecs; import org.opencv.imgproc.Imgproc; public class CustomColorMaps {    public static void main(String args[]) {       // Loading the OpenCV core library       System.loadLibrary(Core.NATIVE_LIBRARY_NAME);     ... Read More

Advertisements