Check if the string contains a particular character in PHP

Right now, will figure out how to discover and check if the string contains a specific character in PHP?

The server-side language PHP is very mainstream in the web industry as a result of its capacity to make dynamic website pages and simplicity of expectation to absorb information for new designers. Working with strings in PHP is very regular on the grounds that in the web we, for the most part, manage web substance and it is essential to see how to perform string tasks.

Right now, will check if any string contains a specific character or not. We will print to the site page on the off chance that it contains the character in the string in any case not. Here’s a PHP content to execute this functionality. We will utilize strpos() function, which anticipates two-parameter, one is the string to check for some other is the character against which string needs to discover the character.


	//We will get the email from form and store in email variable
	$email = $_POST['email'];

	//Inside if, we check using strpos function
	if (strpos($email, '@') === true) {
		print 'There was @ in the e-mail address!';
	} else {
		print 'There was NO @ in the e-mail address!';

The arrival value from strpos() is the main situation in the string at which the character was found. On the off chance that the character wasn’t found at all in the string, strpos() returns bogus. In the event that its first event is discovered, it returns genuine.

In the if condition, we essentially print to the page that the character was available in the event that it is available and strpos returns genuine, else, we print the character is absent.

On the off chance that you like the article, share your musings in the remarks beneath.

Leave a Comment

error: Alert: Content is protected!!