- strstr -- 查找字符串的首次出现,返回字符串从第一次出现的位置开始到该字符串的结尾或开始。
- stristr -- strstr 函数的忽略大小写版本
- strchr -- strstr 函数的别名
- strrchr -- 查找字符串的最后一次出现,返回字符串从最后一次出现的位置开始到该字符串的结尾。
strstr
查找字符串的首次出现,返回字符串从第一次出现的位置开始到该字符串的结尾或开始。
mixed strstr ( string $haystack , mixed $needle [, bool $before_needle = false ] )
参数说明
haystack在该字符串中进行查找。 needle如果 needle 不是一个字符串,那么它将被转换为整型并被视为字符的顺序值来使用。 before_needle若为 TRUE,strstr() 将返回 needle 在 haystack 中的位置之前的部分。
返回值
成功:返回字符串 needle 之前或之后的一部分 失败:如果没找到 needle,将返回 FALSE。
注意
- 该函数区分大小写
- 如果你仅仅想确定 needle 是否存在于 haystack 中,请使用速度更快、耗费内存更少的 strpos()函数
示例
<?php /*【 needle 为单个字符 】 */$email = 'name@example.com';$domain = strstr($email, '@');echo $domain; // 打印 @example.com$user = strstr($email, '@', true); // 从 PHP 5.3.0 起echo $user; // 打印 name ?>
<?php /*【 needle 为数字 】 */$email = 'name@example.com'; //字母a的 ASCII码为 97$behind = strstr($email, 97);echo $behind; // 打印 ame@example.com$front = strstr($email, 97, true); // 从 PHP 5.3.0 起echo $front; // 打印 n ?>
<?php /*【 needle 为字符串 】 */$email = 'name@example.com';$behind = strstr($email, 'ex');echo $behind; // 打印 example.com$front = strstr($email, 'ex', true); // 从 PHP 5.3.0 起echo $front; // 打印 name@ */?>
<?php /*【 needle 为字符串 】 */$email = 'name@example.com';$behind = strstr($email, 'ab');echo $behind; // 返回 false$front = strstr($email, 'ab', true); // 从 PHP 5.3.0 起echo $front; // 返回 false */?>
stristr
strstr() 函数的忽略大小写版本
mixed stristr ( string $haystack , mixed $needle [, bool $before_needle = false ] )
该函数与 strstr() 唯一的区别就是不区分大小写。其他可参考strstr()
<?php $email = 'name@example.com';$behind = stristr($email, 'A');echo $behind; // 打印 ame@example.com$front = stristr($email, 'A', true); // 从 PHP 5.3.0 起echo $front; // 打印 n ?>
strchr
strstr() 函数的别名
mixed strchr ( string $haystack , mixed $needle [, bool $before_needle = false ] )
该函数等同 strstr() 。其他可参考strstr()
$email = 'name@example.com';$behind = strchr($email, 'a');echo $behind; // 打印 ame@example.com$front = strchr($email, 'a', true); // 从 PHP 5.3.0 起echo $front; // 打印 n ?>
strrchr
查找字符串的最后一次出现,返回字符串从最后一次出现的位置开始到该字符串的结尾。
mixed strrchr ( string $haystack , mixed $needle )
参数说明
haystack在该字符串中进行查找。 needle如果 needle 包含了不止一个字符,那么仅使用第一个字符。该行为不同于 strstr()。 如果 needle 不是一个字符串,那么将被转化为整型并被视为字符顺序值。
返回值
成功:返回字符串 needle 之后的一部分 失败:如果没找到 needle,将返回 FALSE。
示例
<?php /*【 needle 为字符 】 */$email = 'name@example.com';$behind = strrchr($email, 'a');echo $behind; // 打印 ample.com ?>
/*【 needle 为字符串 】 */$email = 'name@example.com';$behind = strrchr($email, 'am');echo $behind; // 打印 ample.com ?>
<?php /*【 needle 为数字 】 */$email = 'name@example.com';$behind = strrchr($email, 97);echo $behind; // 打印 ample.com ?>
OneAPM for PHP 能够深入到所有 PHP 应用内部完成应用性能管理 能够深入到所有 PHP 应用内部完成应用性能管理和监控,包括代码级别性能问题的可见性、性能瓶颈的快速识别与追溯、真实用户体验监控、服务器监控和端到端的应用性能管理。想阅读更多技术文章,请访问 OneAPM官方技术博客。

TooptimizePHPcodeforreducedmemoryusageandexecutiontime,followthesesteps:1)Usereferencesinsteadofcopyinglargedatastructurestoreducememoryconsumption.2)LeveragePHP'sbuilt-infunctionslikearray_mapforfasterexecution.3)Implementcachingmechanisms,suchasAPC

PHPisusedforsendingemailsduetoitsintegrationwithservermailservicesandexternalSMTPproviders,automatingnotificationsandmarketingcampaigns.1)SetupyourPHPenvironmentwithawebserverandPHP,ensuringthemailfunctionisenabled.2)UseabasicscriptwithPHP'smailfunct

The best way to send emails is to use the PHPMailer library. 1) Using the mail() function is simple but unreliable, which may cause emails to enter spam or cannot be delivered. 2) PHPMailer provides better control and reliability, and supports HTML mail, attachments and SMTP authentication. 3) Make sure SMTP settings are configured correctly and encryption (such as STARTTLS or SSL/TLS) is used to enhance security. 4) For large amounts of emails, consider using a mail queue system to optimize performance.

CustomheadersandadvancedfeaturesinPHPemailenhancefunctionalityandreliability.1)Customheadersaddmetadatafortrackingandcategorization.2)HTMLemailsallowformattingandinteractivity.3)AttachmentscanbesentusinglibrarieslikePHPMailer.4)SMTPauthenticationimpr

Sending mail using PHP and SMTP can be achieved through the PHPMailer library. 1) Install and configure PHPMailer, 2) Set SMTP server details, 3) Define the email content, 4) Send emails and handle errors. Use this method to ensure the reliability and security of emails.

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Zend Studio 13.0.1
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
