
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 33676 Articles for Programming

149 Views
To print unwanted characters, use preg_match_all(). Let’s say the following is our string with some special characters −$sentence= "M-y Name/i_s John+Doe";We want the output to display only the special characters from the above string i.e.-/_+ExampleThe PHP code is as follows Live Demo OutputThis will produce the following outputThe original value is=M-y Name/i_s John+Doe The unwanted characters are as follows= -/_+

471 Views
Let’s say we have the following array $subject= array('JavaScript','Java','PHP language','Python Language');From the above array, we need to fetch values with the following text $valueToSearch= 'Language';For such match, use preg_match() in PHP.ExampleThe PHP code is as follows Live Demo OutputThis will produce the following outputArray ( [2] => PHP language [3] => Python Language )

10K+ Views
To remove comma, you can replace. To replace, use str_replace() in PHP.Let’s say the following is our input string with comma $name="John,Smith";We want the output after removing comma from the above string is JohnSmithExampleThe PHP code is as follows Live Demo OutputThis will produce the following outputThe actual value is=John,Smith After removing the comma(,)=JohnSmith

480 Views
Use preg_split() in PHP and split with hyphen. Let’s say the following is our input value with numbers and string separated with hyphen $values ="ABC-DEF IJKL-3553435-8990987876";We want the output to beArray ( [0] => ABC-DEF IJKL [1] => 3553435 [2] => 8990987876 )ExampleThe PHP code is as follows Live Demo OutputThis will produce the following output Array ( [0] => ABC-DEF IJKL [1] => 3553435 [2] => 8990987876 )

249 Views
To round amounts, use round() in PHP. Let’s say the following are our input values −$amount=50.78; $quantity=45.5;Convert them to float like this $am=(float) round($amount, 4); $quant=(float) round($quantity, 4);ExampleThe PHP code is as follows Live Demo OutputThis will produce the following output50.78 45.5 The result is=2310.49

337 Views
For this, use preg_match_all(). Let’s say the following is our string $values = 'javamysqlphpmongodbpythonspringhibernatephp';We want to split with specific values like java hibernate phpExampleThe PHP code is as follows Live Demo OutputThis will produce the following outputArray ( [0] => Array ( [0] => java [1] => php [2] => hibernate [3] => php ) [1] => Array ( [0] => java [1] => php [2] => hibernate [3] => php ) )

179 Views
For this, use preg_replace() in PHP. You need to also use Regular Expressions. Let’s say the following is our input −FirstName|John |LastName|Smith|SalaryProvided|2000|5000The expected output is as follows wherein we have replaced a specific character “|” with a whitespace. This character was placed between two numbers 2000 and 5000 −FirstName|John |LastName|Smith|SalaryProvided|2000 5000ExampleThe PHP code is as follows Live Demo OutputThis will produce the following output The result is= FirstName|John |LastName|Smith|SalaryProvided|2000 5000

172 Views
For this, use clone along with set the property name to null.ExampleThe PHP code is as follows Live Demo OutputThis will produce the following outputobject(stdClass)#1 (2) { ["Name"]=> string(4) "John" ["Age"]=> int(20) } object(stdClass)#2 (2) { ["Name"]=> string(4) "John" ["Age"]=> int(20) } object(stdClass)#2 (2) { ["Name"]=> NULL ["Age"]=> NULL } object(stdClass)#1 (2) { ["Name"]=> NULL ["Age"]=> NULL }