Home > Backend Development > PHP Tutorial > PHP strstr函数书上的代码没看懂

PHP strstr函数书上的代码没看懂

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-23 13:56:08
Original
930 people have browsed it

书上有一段关于strstr的代码,是根据提交的反馈信息关键字搜索来发送给不用的邮件

$totaladress = 'deedback@example.com';if(strstr($feedback,'shop')){    $totaladress = 'retail@example.com';}else {    $totaladress = 'account@example.com';}
Copy after login

我看w3school上的讲解,strstr搜索到目标字符串后返回剩余部分,也就是字符串,否则返回false,那这里函数返回值直接用作if判断条件是什么意思?
谢谢讲解


回复讨论(解决方案)

strstr() 函数搜索一个字符串在另一个字符串中的第一次出现。
该函数返回字符串的其余部分(从匹配点)。如果未找到所搜索的字符串,则返回 false。

echo strstr("Hello world!","world");
?>
输出:
world!

if判断时 括号内会转成布尔值 字符串=true
你可以理解成一种简写
$a = strstr($feedback,'shop');
if($a != false){}

if判断时 括号内会转成布尔值 字符串=true
你可以理解成一种简写
$a = strstr($feedback,'shop');
if($a != false){}


谢谢,看了你的答案,再去网上看了看,我懂了
Related labels:
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
Latest Issues
PHP using ENUM in properties
From 1970-01-01 08:00:00
0
0
0
github student discount
From 1970-01-01 08:00:00
0
0
0
laravel scheduled task weekly
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template