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 More
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 More
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 More
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 More
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 More
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 More
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 More
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 More
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 More
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
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Economics & Finance