How to Check if String Contains Comma in PHP?
Hi Dev,
In this example, I will show you How do I Check if String Contains Comma PHP?. I explained simply step by step How to Check if String Contains Comma PHP?. This article will give you simple example of Check a Given Value Contains Comma in PHP. In this article, we will implement a Check if String Contains a Comma Character in PHP.
There are example to Check if String Contains Check if a String Contains a Comma in PHP. in this example, we will use to strpos() and str_contains both function to Check if String Contains comma. so Let's the following example with output.
Example 1:
index.php
<?php
// Check to see if string contains special characters (excluding Comma)
$string = "NiceSnippets.com is the Bast Site";
if (strpos($string, ',')) {
echo 'Found Comma';
}else{
echo 'Not a Found comma';
}
?>
Output:
Not a Found comma
Example 2:
index.php
<?php
// Check to see if string contains special characters (excluding Comma)
$string = "NiceSnippet's.com is the Bast Site";
if (str_contains($string, ',')) {
echo 'true';
}else{
echo 'false';
}
?>
Output:
true
I hope it could help you...
- How To Use Php Conditional Statement Example
- How to Check if String Contains Regex in PHP?
- PHP Array_column() Function Example
- PHP Generate List of Random Numbers Between 0 and 100 Example
- How to User Login with Facebook in PHP?
- How to Explode Every Character into Array Using PHP Example?
- PHP Form Validation Tutorial
- PHP Convert XML to JSON Example