Home > Backend Development > PHP Tutorial > PHP simple method to determine whether a string contains another string

PHP simple method to determine whether a string contains another string

WBOY
Release: 2016-07-29 08:56:34
Original
948 people have browsed it

The example in this article describes how PHP simply determines whether a string contains another string. Share it with everyone for your reference, the details are as follows:

When using PHP to determine whether a string contains a simple substring, we usually use the two functions strpos() or stristr(), but... If the position of this string is at index 0, that is, at the beginning of the string to be matched, there will be a problem.

Of course we still have a solution. Here is a stupid solution, but it is easier to use. It applies to both Chinese and English punctuation marks.

The code is as follows:

function checkStr($str,$target)
{
  $tmpArr = explode($str,$target);
  //print_r($tmpArr);
  if(count($tmpArr)>1)return true;
  else return false;
}
$result = checkStr("sdfg","bsdfsldkfj");
var_dump($result);

Copy after login

Readers who are interested in more PHP-related content can check out the special topics on this site: "Summary of PHP Office Document Skills (Including Word, Excel, Access, PPT)", "php Date and Time" Usage Summary", "php object-oriented programming introductory tutorial", "php string (string) usage summary", "php+mysql database operation introductory tutorial" and "php common database operation skills summary"

I hope that what this article has said will be helpful Everyone PHP programming helps.

The above introduces the method of PHP to simply determine whether a string contains another string, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template