Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any function like contains from Java for PHP?

Tags:

java

php

I would like to know if is there any function that search a string within string and return boolean value in PHP, telling if the string contains or not, like the method contains in Java?

like image 431
Marcos Avatar asked Jul 13 '12 19:07

Marcos


People also ask

How do I check if a string contains a specific word in PHP?

Answer: Use the PHP strpos() Function You can use the PHP strpos() function to check whether a string contains a specific word or not. The strpos() function returns the position of the first occurrence of a substring in a string. If the substring is not found it returns false .

How do I check if a string contains a specific character in PHP?

The str_contains is a new function that was introduced in PHP 8. This method is used to check if a PHP string contains a substring. The function checks the string and returns a boolean true in case it exists and false otherwise.

How use contains method in Java?

contains() method searches the sequence of characters in the given string. It returns true if sequence of char values are found in this string otherwise returns false. Here conversion of CharSequence to a String takes place and then indexOf method is called.

Is there a Contains function in Python?

contains() function is used to test if pattern or regex is contained within a string of a Series or Index. The function returns boolean Series or Index based on whether a given pattern or regex is contained within a string of a Series or Index.

How do you check if a word contains a letter in Java?

The contains() method checks whether a string contains a sequence of characters. Returns true if the characters exist and false if not.

Does string contain substring Java?

You can use contains(), indexOf() and lastIndexOf() method to check if one String contains another String in Java or not. If a String contains another String then it's known as a substring. The indexOf() method accepts a String and returns the starting position of the string if it exists, otherwise, it will return -1.


1 Answers

You can try strpos(), http://php.net/strpos

$str = "This is a sample string.";
$findMe = "sample";

if (strpos($str, $findMe) !== false) {
    // you found me!
}
like image 100
newfurniturey Avatar answered Oct 23 '22 22:10

newfurniturey