
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
Make Sure String Has No Whitespace in PHP
To check whether a string has no whitespace, use the preg_match() in PHP.
The syntax is as follows
preg_match('/\s/',$yourVariableName);
Example
The PHP code is as follows
<!DOCTYPE html> <html> <body> <?php $name="John Smith"; if ( preg_match('/\s/',$name) ){ echo "The name (",$name,") has the space"; } else { echo "The Name (",$name,") has not the space"; } ?> </body> </html>
Output
This will produce the following output
The name (John Smith) has the space
Advertisements