兼容:(PHP 3, PHP 4, PHP 5)
strpos -- Find position of first occurrence of a string
查找字符在字符串第一次出现的位置
语法:int strpos ( string haystack, mixed needle [, int offset] )
返回值:整数
函数种类: 资料处理
内容说明:
英文:
Returns the numeric position of the first occurrence of needle in the haystack string. Unlike the strrpos(), this function can take a full string as the needle parameter and the entire string will be used.
If needle is not found, strpos() will return boolean FALSE.
If needle is not a string, it is converted to an integer and applied as the ordinal value of a character.
The optional offset parameter allows you to specify which character in haystack to start searching. The position returned is still relative to the beginning of haystack.
中文:
传回参数 needle在字串 haystack中第一次出现的位置,以数字表示。不像strrpos( ),此函式可以取参数 needle全部的字串,而且会使用全部的字串。如果找不到参数 needle,则传回 false。
如果参数 needle不是字串时,它会转换成整数并且按照字元的顺序值来使用。
参数 offset允许你去指定在 haystack中从那一个字元开始搜寻,传回的位置依然是相对於 haystack的起点。
*值得注意的是 needle 只能是一个字符,中文字等就不适合了。
例子讲解:<font color="#000000">
<font color="#0000BB"></font><font color="#007700"></font><font color="#0000BB">php<br><br>$mystring </font><font color="#007700">= </font><font color="#DD0000">'abc'</font><font color="#007700">;<br><br></font><font color="#0000BB">$findme</font><font color="#007700">= </font><font color="#DD0000">'a'</font><font color="#007700">;<br><br></font><font color="#0000BB">$pos </font><font color="#007700">= </font><font color="#0000BB">strpos</font><font color="#007700">(</font><font color="#0000BB">$mystring</font><font color="#007700">, </font><font color="#0000BB">$findme</font><font color="#007700">);<br><br><br><br></font><font color="#FF8000">// Note our use of ===.Simply == would not work as expected<br><br>// because the position of 'a' was the 0th (first) character.<br><br></font><font color="#007700">if (</font><font color="#0000BB">$pos </font><font color="#007700">=== </font><font color="#0000BB">false</font><font color="#007700">) {<br><br>echo </font><font color="#DD0000">"The string '$findme' was not found in the string '$mystring'\";<br><br>} else {<br><br>echo \"The string '$findme' was found in the string '$mystring'\";<br><br>echo \" and exists at position $pos\";<br><br>}<br><br><br><br>// We can search for the character, ignoring anything before the offset<br><br>$newstring = 'abcdef abcdef';<br><br>$pos = strpos($newstring, 'a', 1); // $pos = 7, not 0<br><br>?></font>
</font>
strpos()与substr_count()对比:<font color="#000000">
<font color="#0000BB"></font><font color="#007700"></font><font color="#0000BB">php<br><br>$mystring </font><font color="#007700">= </font><font color="#DD0000">"Hello Chris\";<br><br>if (substr_count($mystring, \"Hello\") == 0)<br><br>echo \"no\";<br><br>// same as:<br><br>if (strpos($mystring, \"Hello\") === false)<br><br>echo \"no\";<br><br>?></font>
</font>
对比下面两个代码注意数字情况下,容易出现的错误,数字整数情况下不能看成字符串。<font color="#000000">
<font color="#0000BB"></font><font color="#007700"></font><font color="#0000BB">php<br><br>$val1</font><font color="#007700">=</font><font color="#0000BB">123</font><font color="#007700">;<br><br></font><font color="#0000BB">$val2</font><font color="#007700">=</font><font color="#DD0000">"123,456,789\";<br><br>if (strpos($val2, $val1)!==false) echo \"matched\";<br><br>else echo \"not matched\";<br><br>?></font>
</font>
<font color="#000000">
<font color="#0000BB">结果为: not matched</font>
</font>
<font color="#000000">
<font color="#0000BB"></font><font color="#007700"></font><font color="#0000BB">php<br><br>$val1</font><font color="#007700">=(string)</font><font color="#0000BB">123</font><font color="#007700">;<br><br></font><font color="#0000BB">$val2</font><font color="#007700">=</font><font color="#DD0000">"123,456,789\";<br><br>if (strpos($val2, $val1)!==false) echo \"matched\";<br><br>else echo \"not matched\";<br><br>?></font>
</font>
<font color="#000000">
<font color="#0000BB">结果为:not matched</font>
</font>

设置无线网络很常见,但选择或更改网络类型可能会令人困惑,尤其是在您不知道后果的情况下。如果您正在寻找有关如何在Windows11中将网络类型从公共更改为私有或反之亦然的建议,请继续阅读以获取一些有用的信息。Windows11中有哪些不同的网络配置文件?Windows11附带了许多网络配置文件,这些配置文件本质上是可用于配置各种网络连接的设置集。如果您在家中或办公室有多个连接,这将非常有用,因此您不必每次连接到新网络时都进行所有设置。专用和公用网络配置文件是Windows11中的两种常见类型,但通

Part1聊聊Python序列类型的本质在本博客中,我们来聊聊探讨Python的各种“序列”类,内置的三大常用数据结构——列表类(list)、元组类(tuple)和字符串类(str)的本质。不知道你发现没有,这些类都有一个很明显的共性,都可以用来保存多个数据元素,最主要的功能是:每个类都支持下标(索引)访问该序列的元素,比如使用语法Seq[i]。其实上面每个类都是使用数组这种简单的数据结构表示。但是熟悉Python的读者可能知道这3种数据结构又有一些不同:比如元组和字符串是不能修改的,列表可以

随着短视频平台的盛行,视频矩阵账号营销已成为一种新兴营销方式。通过在不同平台上创建和管理多个账号,企业和个人能够实现品牌推广、粉丝增长和产品销售等目标。本文将为您探讨如何有效运用视频矩阵账号,并介绍不同类型的视频矩阵账号。一、视频矩阵账号怎么做?要想做好视频矩阵账号,需要遵循以下几个步骤:首先要明确你的视频矩阵账号的目标是什么,是为了品牌传播、粉丝增长还是产品销售。明确目标有助于制定相应的策略。2.选择平台:根据你的目标受众,选择合适的短视频平台。目前主流的短视频平台有抖音、快手、火山小视频等。

Go函数可以返回多个不同类型的值,返回值类型在函数签名中指定,并通过return语句返回。例如,函数可以返回一个整数和一个字符串:funcgetDetails()(int,string)。实战中,一个计算圆面积的函数可以返回面积和一个可选错误:funccircleArea(radiusfloat64)(float64,error)。注意事项:如果函数签名未指定类型,则返回空值;建议使用显式类型声明的return语句以提高可读性。

使用动态语言一时爽,代码重构火葬场。相信你一定听过这句话,和单元测试一样,虽然写代码的时候花费你少量的时间,但是从长远来看,这是非常值得的。本文分享如何更好的理解和使用Python的类型提示。1、类型提示仅在语法层面有效类型提示(自PEP3107开始引入)用于向变量、参数、函数参数以及它们的返回值、类属性和方法添加类型。Python的变量类型是动态的,可以在运行时修改,为代码添加类型提示,仅在语法层面支持,对代码的运行没有任何影响,Python解释器在运行代码的时候会忽略类型提示。因此类型提

随着互联网的快速发展,自媒体已经成为了信息传播的重要渠道。自媒体平台为个人和企业提供了一个展示自己、传播信息的舞台。目前,市场上主要的自媒体平台有微信公众号、今日头条、一点资讯、企鹅媒体平台等。这些平台各有特色,为广大自媒体从业者提供了丰富的创作空间。接下来,我们将对这些平台进行详细介绍,并探讨自媒体平台的类型。一、主要的自媒体平台有哪些?微信公众号是腾讯推出的自媒体平台,为个人和企业用户提供信息发布和传播服务。它分为服务号和订阅号两种类型,服务号主要为企业提供服务,而订阅号则侧重于资讯传播。由

C++函数有以下类型:简单函数、const函数、静态函数、虚函数;特性包括:inline函数、默认参数、引用返回、重载函数。例如,calculateArea函数使用π计算给定半径圆的面积,并将其作为输出返回。

Python是一种强大的编程语言,但在使用过程中经常会遇到类型不匹配的错误。这种错误是由数据类型不匹配或者变量类型不正确引起的。在本文中,我们将给出一些如何解决这些类型不匹配错误的实用建议。1.了解Python数据类型在Python中,有多种数据类型,包括整数、浮点数、字符串、列表、元组、字典等。因此,为了避免类型不匹配的错误,应该先了解不同数据类型的特点和


Alat AI Hot

Undresser.AI Undress
Apl berkuasa AI untuk mencipta foto bogel yang realistik

AI Clothes Remover
Alat AI dalam talian untuk mengeluarkan pakaian daripada foto.

Undress AI Tool
Gambar buka pakaian secara percuma

Clothoff.io
Penyingkiran pakaian AI

AI Hentai Generator
Menjana ai hentai secara percuma.

Artikel Panas

Alat panas

DVWA
Damn Vulnerable Web App (DVWA) ialah aplikasi web PHP/MySQL yang sangat terdedah. Matlamat utamanya adalah untuk menjadi bantuan bagi profesional keselamatan untuk menguji kemahiran dan alatan mereka dalam persekitaran undang-undang, untuk membantu pembangun web lebih memahami proses mengamankan aplikasi web, dan untuk membantu guru/pelajar mengajar/belajar dalam persekitaran bilik darjah Aplikasi web keselamatan. Matlamat DVWA adalah untuk mempraktikkan beberapa kelemahan web yang paling biasa melalui antara muka yang mudah dan mudah, dengan pelbagai tahap kesukaran. Sila ambil perhatian bahawa perisian ini

PhpStorm versi Mac
Alat pembangunan bersepadu PHP profesional terkini (2018.2.1).

SublimeText3 versi Mac
Perisian penyuntingan kod peringkat Tuhan (SublimeText3)

MinGW - GNU Minimalis untuk Windows
Projek ini dalam proses untuk dipindahkan ke osdn.net/projects/mingw, anda boleh terus mengikuti kami di sana. MinGW: Port Windows asli bagi GNU Compiler Collection (GCC), perpustakaan import yang boleh diedarkan secara bebas dan fail pengepala untuk membina aplikasi Windows asli termasuk sambungan kepada masa jalan MSVC untuk menyokong fungsi C99. Semua perisian MinGW boleh dijalankan pada platform Windows 64-bit.

ZendStudio 13.5.1 Mac
Persekitaran pembangunan bersepadu PHP yang berkuasa
