How to Check if String Contains Comma in PHP?

03-Apr-2023

.

Admin

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...

#PHP