PHP Check if String Contains Only Alphabets With Example

Hello Friends Today, through this tutorial, I will tell you How do you check if a string contains only alphabetic characters using PHP With Example? You can check if a string contains only alphabetic characters in PHP using regular expressions. Here’s how you can do it:

<?php
$string = "OnlyAlphabets";
if (ctype_alpha($string)) {
echo "The string contains only alphabetic characters.";
} else {
echo "The string contains non-alphabetic characters.";
}
?>

The `ctype_alpha()` function checks whether all characters in the string are alphabetic. It returns `true` if all characters are alphabetic, and `false` otherwise.

Alternatively, you can use regular expressions:

<?php
$string = "OnlyAlphabets";
if (preg_match('/^[A-Za-z]+$/', $string)) {
echo "The string contains only alphabetic characters.";
} else {
echo "The string contains non-alphabetic characters.";
}
?>

This regular expression `^[A-Za-z]+$` matches the string only if it contains one or more alphabetic characters from A to Z (both uppercase and lowercase). If the string contains any non-alphabetic character or is empty, the match fails.

Cialis (Tadalafil) är den främsta konkurrenten till Viagra (Sildenafil) på marknaden för erektil dysfunktion. köpa Cialis i Sverige föredras av många på grund av sin längre varaktighet och anses vara det mest kostnadseffektiva varumärkesbaserade ED-läkemedlet som finns tillgängligt i Sverige. Cialis finns i två varianter: Cialis och Cialis Daily, och fyra olika doseringar: 2,5 mg, 5 mg, 10 mg och 20 mg, erbjuder Cialis också en rad olika alternativ för att passa patientens behov.