Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles on Trending Technologies
Technical articles with clear explanations and examples
How to do bold and simple text in the same line using the echo in php?
In PHP, you can combine bold and regular text in the same line using HTML tags within your echo statement. The most effective approach is to use the tag for bold text and regular text outside it. Using Strong Tags The simplest way to create bold text alongside regular text is using the HTML tag − This is bold text and this is regular text. Using CSS Styling You can also use CSS font-weight property with tags for more control over styling − ...
Read MoreHow to deal with multi-byte UTF-8 strings in JavaScript and fix the empty delimiter/separator issue
In PHP, when working with multi-byte UTF-8 strings, using preg_split() with the '//u' pattern and the PREG_SPLIT_NO_EMPTY flag helps handle empty delimiter issues and properly splits UTF-8 characters. Syntax preg_split('//u', $string, -1, PREG_SPLIT_NO_EMPTY) Parameters The key components of this approach − '//u' − Empty pattern with Unicode modifier for UTF-8 support $string − The input string to split -1 − No limit on number of splits PREG_SPLIT_NO_EMPTY − Removes empty elements from result Example Here's how to split UTF-8 strings into individual characters − ...
Read MoreForeach loop with two arrays and if-condition evaluation to find matching values PHP?
In PHP, you can use nested foreach loops with if-conditions to find matching values between two arrays. This approach compares each element from the first array against all elements in the second array. Problem Statement Given two arrays, we need to find the common elements between them ? $firstArray = array(10, 20, 30, 40, 50); $secondArray = array(100, 80, 30, 40, 90); Expected output should be ? 30 40 Using Nested Foreach Loops The most straightforward approach uses nested foreach loops to compare each element ? ...
Read MoreGet Last Part of URL in PHP?
To get the last part of a URL in PHP, you can use several methods depending on your needs. The most common approaches are using basename(), pathinfo(), or regular expressions with preg_match(). Using basename() The simplest method is using PHP's built-in basename() function, which extracts the filename from a path ? The last part is: 9989809898 Using pathinfo() The pathinfo() function provides more detailed information about the URL path ? The last part is: 9989809898 Using Regular Expressions For more ...
Read MorePrinting Unwanted Characters with PHP "preg_match"?
To print unwanted characters from a string, use preg_match_all() with a regex pattern that matches non−alphanumeric characters. This function finds all matches and stores them in an array. Syntax preg_match_all(pattern, subject, matches) Parameters The function accepts the following parameters ? pattern − The regular expression pattern to search for subject − The input string to search in matches − Array to store all matches found Example Let's extract special characters from a string containing unwanted symbols ? The original value is: M-y Name/i_s ...
Read MoreSearch for PHP array element containing string?
In PHP, you can search for array elements containing a specific string using several methods. The most common approaches include preg_match() for pattern matching, array_filter() for functional filtering, and simple string functions like strpos(). Using preg_match() with foreach The preg_match() function allows pattern−based searching with regular expressions ? Array ( [2] => PHP language [3] => Python Language ) Using array_filter() with strpos() A simpler approach using array_filter() for case−insensitive substring matching ? Array ( ...
Read MoreRemove comma from a string in PHP?
In PHP, you can remove commas from a string using the str_replace() function. This function searches for a specific character or substring and replaces it with another value or removes it entirely. Syntax str_replace(search, replace, subject) Parameters: search − The character or string to find (comma in our case) replace − What to replace it with (empty string to remove) subject − The original string to process Example Let's remove commas from a string containing a person's name ? The actual value is = John, ...
Read MorePHP preg_split with hyphen?
In PHP, you can use preg_split() to split strings at specific patterns, including hyphens. The preg_split() function uses regular expressions to define where the string should be split, giving you more control than simple explode(). Basic Hyphen Splitting To split a string at every hyphen, use a simple pattern ? Array ( [0] => apple [1] => banana [2] => cherry ) Conditional Splitting with Lookahead For more complex splitting, such as splitting only at hyphens followed ...
Read MoreHow to pass reference parameters PHP?
In PHP, you can pass parameters by reference using the & symbol before the parameter name in the function definition. This allows the function to modify the original variable instead of working with a copy. Syntax To pass a parameter by reference, prefix the parameter with & in the function definition ? function functionName(&$parameter) { // Modify the original variable } Example Here's how to pass a reference parameter to modify the original variable ? The actual value is = 900 The modified ...
Read MoreReplacing specific characters from a matched string in PHP regular expression where we don't know the number of instances of the match?
In PHP, you can use preg_replace() with regular expressions to replace specific characters from matched strings, even when you don't know how many instances exist. This is particularly useful for parsing delimited data where certain delimiters need conditional replacement. Problem Example Let's say we have this input string where we want to replace the pipe character "|" only when it appears between two numbers − FirstName|John |LastName|Smith|SalaryProvided|2000|5000 The expected output should replace the "|" between 2000 and 5000 with a space − FirstName|John |LastName|Smith|SalaryProvided|2000 5000 Solution Using preg_replace() The ...
Read More