<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[沧海一粟]]></title> 
<link>http://www.dzhope.com/index.php</link> 
<description><![CDATA[Web系统架构与服务器运维,php开发]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[沧海一粟]]></copyright>
<item>
<link>http://www.dzhope.com/post//</link>
<title><![CDATA[strpos -- 找出字符串第一次出现的位置（从左到右查找）]]></title> 
<author>jed &lt;jed521@163.com&gt;</author>
<category><![CDATA[代码编程]]></category>
<pubDate>Thu, 07 Sep 2006 08:29:40 +0000</pubDate> 
<guid>http://www.dzhope.com/post//</guid> 
<description>
<![CDATA[ 
	strpos<br/>(PHP 3, PHP 4, PHP 5)<br/>strpos -- &nbsp;找出字符串第一次出现的位置（从左到右查找） <br/>说明<br/>int strpos ( string haystack, mixed needle [, int offset] )<br/><br/>传回参数 needle在字符串 haystack中第一次出现的位置，以数字表示。不像strrpos( )，此函数可以取参数 needle全部的字符串，而且会使用全部的字符串。<br/>如果找不到参数 needle，则传回 false。参数 offset 可省略，用来表示从 offset 开始找。<br/>语法<br/>从开头到末尾查找字符串中指定字符<br/>StrPos('源字符串','要查找的字符')<br/>从指定开始处查找<br/>StrPos('源字符串','要查找的字符',查找的开始位置)<br/>警告 <br/>本函数可能返回布尔值 FALSE，但也可能返回一个与 FALSE 等值的非布尔值，例如 0 或者 ""。请参阅布尔类型章节以获取更多信息。应使用 === 运算符来测试本函数的返回值。<br/> <br/><br/>注: 该函数可安全用于二进制对象。<br/>例子 1. strpos() examples<br/><?php<br/>$mystring = 'abc';<br/>$findme &nbsp; = 'a';<br/>$pos = strpos($mystring, $findme);<br/>// Note our use of ===. &nbsp;Simply == would not work as expected<br/>// because the position of 'a' was the 0th (first) character.<br/>if ($pos === false) &#123; <br/> &nbsp; &nbsp;echo "The string '$findme' was not found in the string '$mystring'";<br/>&#125; else &#123; <br/> &nbsp; &nbsp;echo "The string '$findme' was found in the string '$mystring'";<br/> &nbsp; &nbsp;echo " and exists at position $pos";<br/>&#125;<br/>// We can search for the character, ignoring anything before the offset<br/>$newstring = 'abcdef abcdef';<br/>$pos = strpos($newstring, 'a', 1); // $pos = 7, not 0<br/>?> &nbsp;<br/> <br/><br/>如果参数 needle不是字符串时，它会转换成整数并且按照字符的顺序值来使用。<br/>参数 offset允许你去指定在 haystack中从那一个字符开始搜寻，传回的位置依然是相对于 haystack的起点。<br/>参见 strrpos(), stripos(), strripos(), strrchr(), substr(), stristr(), and strstr(). <br/>另：<br/>可以用中文的。只不过按照常理的一个汉字占两个字母位……<br/>例如：<br/><?<br/>$foo="这是一个例子，测试用。";<br/>$num=strpos($foo,"个");<br/>echo"$num";<br/>?><br/>你看到的结果是6。为什么会这样？因为他是采用数组保存的（我猜应该是），所以是以"0"开头的。<br/>也就是说，如果<br/>$foo="this is a sample,just for test.";<br/>$num=strpos($foo,"t");<br/>结果将是0，对，没错。<br/>所以使用该函数注意两点：<br/>一，可以应用于中文（PHP中文手册说明有误）；<br/>二，他的计算方式。<br/>如果想计算一个英文串中字符出现在第几个，$num++<br/>如果是中文，$num=($num+1)/2（这个并不全对，还要考虑一下标点符号全角半角的问题，自己想想吧）<br/>还要注意，不仅可以应用中文字，还可以应用中文字符传串（既然一个中文字可以，几个当然也可以了）。（手册中“一个字元”何解？？？）<br/>
]]>
</description>
</item><item>
<link>http://www.dzhope.com/post//#blogcomment</link>
<title><![CDATA[[评论] strpos -- 找出字符串第一次出现的位置（从左到右查找）]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.dzhope.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>