<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>飞扬轻狂&#039;s blog &#187; fallseir</title>
	<atom:link href="http://blog.fallseir.com/tag/fallseir/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.fallseir.com</link>
	<description>我心飞扬 我意轻狂</description>
	<lastBuildDate>Thu, 06 May 2010 07:13:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/><cloud domain='blog.fallseir.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>谨慎的在c++中使用cin进行交互</title>
		<link>http://blog.fallseir.com/2008/10/note_std_cin/</link>
		<comments>http://blog.fallseir.com/2008/10/note_std_cin/#comments</comments>
		<pubDate>Fri, 24 Oct 2008 09:34:28 +0000</pubDate>
		<dc:creator>飞扬轻狂</dc:creator>
				<category><![CDATA[随笔]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[cin]]></category>
		<category><![CDATA[fallseir]]></category>
		<category><![CDATA[learn]]></category>

		<guid isPermaLink="false">http://blog.fallseir.com/?p=107</guid>
		<description><![CDATA[在使用c++ 进行控制台交互时 也许你也容易忽略掉的细节 &#8211; 飞扬轻狂 20081024 fallseir[at]gmail.com http://blog.fallseir.com/2008/10/note_std_cinnote_std_cin/ 注意1： &#8221; cin >> value &#8221; 没有正确的读取换行 注意2： 不匹配的类型 将导致输入流错误 而在其后的调用中自动返回 注意3： 空字符 在使用 >> 赋值给变量时将自动过滤 直到读入非空字符为止 出错的代码 ！！ $ vim 02-05-BasicIO-err.cpp --------------------------------------------- #include using namespace std; int main( int argc, char *argv[] ){ int num; string str,line; cout > num; cout > str; cout]]></description>
			<content:encoded><![CDATA[<p>在使用c++ 进行控制台交互时 也许你也容易忽略掉的细节</p>
<p>&#8211; 飞扬轻狂 20081024 fallseir[at]gmail.com</p>
<p>http://blog.fallseir.com/2008/10/note_std_cinnote_std_cin/</p>
<p>注意1： &#8221; cin >> value &#8221; 没有正确的读取换行<br />
注意2： 不匹配的类型 将导致输入流错误 而在其后的调用中自动返回<br />
注意3： 空字符 在使用 >> 赋值给变量时将自动过滤 直到读入非空字符为止</p>
<p>出错的代码 ！！</p>
<pre>
$ vim 02-05-BasicIO-err.cpp
---------------------------------------------
#include <iostream>
using namespace std;
int main( int argc, char *argv[] ){
  int num;
  string str,line;

  cout << "Please enter a number:" ;
  cin >> num;
  cout << "Please enter a text :" ;
  cin >> str;
  cout << "Please enter some words :" ;
  getline( cin, line );

  cout << endl;
  cout << "number : " << num << endl;
  cout << "text : " << str << endl;
  cout << "some words : " << line << endl;

  return 0;
}
---------------------------------------------
$ g++ 02-05-BasicIO-err.cpp
$ a.out # 貌似正确的输入
----------------
Please enter a number:12<enter>
Please enter a text :message<enter>
Please enter some words :
number : 12
text : message
some words :
----------------
/*
 分析原因：
 第二次输入 "message" 的时候 自动过滤前次的<enter> 并得到了正确的值
 getline 的时候 因为输入流中还有一个 <enter> 没有被读取 所以没有等待用户输入，直接返回了
 */
--------------------
$ a.out # 貌似正确的结果
----------------
Please enter a number:13 message some words in the line <enter>
Please enter a text <img src='http://blog.fallseir.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> lease enter some words :
number : 13
text : message
some words :  some words in the line
----------------
/*
 分析原因：
 cin >> str 的时候 从流中读取了 "message"
 getline 的时候 读取了流中剩下的内容
 */
--------------------
$ a.out # 错误的开始
----------------
Please enter a number:a
Please enter a text <img src='http://blog.fallseir.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> lease enter some words :
number : 6696948
text :
some words :
----------------
/*
 分析原因：
 cin >> num 的时候 从流中读取了不匹配的数据 "a" ，cin 进入异常状态
 cin >> str 和 getline 的时候 因为流异常 所以没有进行读取
 */
--------------------
</pre>
<p>优化的严谨的代码</p>
<pre>
$ vim 02-05-BasicIO.cpp
---------------------------------------------
#include <iostream>
using namespace std;
int main( int argc, char *argv[] ){
  int num;
  string str,line;
  string tmp;

  cout << "Please enter a number:" ;
  cin >> num;
  while(cin.fail()){ // 如果出现错误
    cin.clear(); // 清除错误
    getline(cin,tmp); // 清除缓存
    cerr << "Error input!!,Please try again" << endl;
    cin >> num;
  }
  getline(cin,tmp); // 使用getline清除缓存，因为 >> 操作符不会对末尾的 <enter> 进行读取 

  cout << "Please enter a text :" ;
  cin >> str;
  getline(cin,tmp);

  cout << "Please enter some words :" ;
  getline( cin, line );
  cout << endl;
  cout << "number : " << num << endl;
  cout << "text : " << str << endl;
  cout << "some words : " << line << endl;

  return 0;
}

---------------------------------------------
----------------
$ a.out
----------------
Please enter a number:123 message test words!
Please enter a text :word and message
Please enter some words :some words in the line!

number : 123
text : word
some words : some words in the line!
----------------
</pre>
<p>-- </p>
<p>http://blog.fallseir.com/2008/10/note_std_cinnote_std_cin/</p>
<p>飞扬轻狂<br />
fallseir[at]gmail.com<br />
blog.fallseir.com<br />
2008年10月24日<br />
转载请注明</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.fallseir.com/2008/10/note_std_cin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>一段用于替换字符串中指定的key的代码</title>
		<link>http://blog.fallseir.com/2008/05/mapkeys/</link>
		<comments>http://blog.fallseir.com/2008/05/mapkeys/#comments</comments>
		<pubDate>Tue, 06 May 2008 09:58:02 +0000</pubDate>
		<dc:creator>飞扬轻狂</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[fallseir]]></category>

		<guid isPermaLink="false">http://blog.fallseir.com/?p=89</guid>
		<description><![CDATA[一段用于替换字符串中指定的key的代码 &#8211;[[User:Fallseir&#124;飞扬轻狂]] 2008年5月6日 (二) 02:32 (PDT) $str=mapKeys($formatstr,$maps); $str=&#8220;replace&#160;this&#160;template&#160;string&#160;!the&#160;key&#160;maps&#160;is&#160;herekey1=&#62;{key1},key{{2=&#62;{key{2},key3}=&#62;{key3{}}&#8221;;echo&#160;mapKeys($str&#160;&#160;,array(&#8220;key1&#8243;=&#62;&#8220;value&#160;1&#8243;&#160;&#160;,&#8220;key{2&#8243;=&#62;&#8220;value&#160;2&#8243;&#160;&#160;,&#8220;key3}&#8221;=&#62;&#8220;value&#160;3&#8243;&#160;&#160;));echo&#160;&#8220;\n&#8221; output>> replace this template string !the key maps is here key1=>value 1,key{2=>value 2,key3}=>value 3 abc[the abc value]}}%[%}%%%]%{%[0}%%,%%%,{key],%%,%%[the %value% 2],%%[the %value% 2],%$$%%{,%, abc%%%%%%%%%,%%%,%key%,%%,%%%key,2%,%,%$$%%,%, $ php -r &#8216;highlight_file(&#8220;test.php&#8221;);&#8217; &#60;?php/**&#160;test&#160;*/$str="replace&#160;this&#160;template&#160;string&#160;!the&#160;key&#160;maps&#160;is&#160;herekey1=&#62;{key1},key{{2=&#62;{key{2},key3}=&#62;{key3{}}";echo&#160;mapKeys($str&#160;&#160;,array("key1"=&#62;"value&#160;1"&#160;&#160;,"key{2"=&#62;"value&#160;2"&#160;&#160;,"key3}"=&#62;"value&#160;3"&#160;&#160;));echo&#160;"\n"; $str="abc{key}{}}%{%{}%%%}%{{%{0{}%%,%%%,{key},%%,%%{key,2},%%{key,2},%$$%%{,%,";echo&#160;mapKeys($str,array("key"=&#62;"[the&#160;abc&#160;value]","key,2"=&#62;"[the&#160;%value%&#160;2]"));echo&#160;"\n"; $str="abc%%%%%%%%%,%%%,%key%,%%,%%%key,2%,%,%$$%%,%,";echo&#160;mapKeys($str,array("key"=&#62;"[the&#160;abc&#160;value]"&#160;&#160;&#160;&#160;,"key,2"=&#62;"[the&#160;%value%&#160;2]"),"&#124;%&#124;");echo&#160;"\n";//end&#160;test*//*$&#160;php&#160;test.phpoutput&#62;&#62;replace&#160;this&#160;template&#160;string&#160;!the&#160;key&#160;maps&#160;is&#160;herekey1=&#62;value&#160;1,key{2=&#62;value&#160;2,key3}=&#62;value&#160;3abc[the&#160;abc&#160;value]}}%[%}%%%]%{%[0}%%,%%%,{key],%%,%%[the&#160;%value%&#160;2],%%[the&#160;%value%&#160;2],%$$%%{,%,abc%%%%%%%%%,%%%,%key%,%%,%%%key,2%,%,%$$%%,%,&#160;&#160;*/&#160;&#160;/**&#160;*&#160;使用maps中定义的value替换对应其key的由开始标记字符和结束标记字符包含的字符串&#160;*&#160;*&#160;当标记对外开始标记后跟着开始标记时或结束标记时表示第一个开始标记为转义符&#160;*&#160;当标记对内开始标记后跟着结束标记时表示第一个开始标记为转义符&#160;*&#160;末尾没有匹配的开始标记将原样输出&#160;*/function&#160;mapKeys($str,$maps,$fstart=null,$fend=null){&#160;&#160;if(!$fstart){&#160;&#160;&#160;&#160;&#160;&#160;$fstart="{";&#160;&#160;&#160;&#160;&#160;&#160;$fend="}";&#160;&#160;}&#160;&#160;if(!$fend){&#160;&#160;&#160;&#160;$fend=$fstart;&#160;&#160;&#160;&#160;&#160;&#160;}&#160;&#160;&#160;&#160;//&#160;如果标记相同则使用mapKeysBase进行替换&#160;&#160;if($fstart==$fend){return&#160;mapKeysBase($str,$maps,$fstart);}&#160;&#160;&#160;$index=0;&#160;&#160;$offset=0;&#160;&#160;while(false!==($index=strpos($str,$fstart,$offset))){&#160;&#160;&#160;&#160;#&#160;找到开始标记,处理开始标记之前的数据&#160;&#160;&#160;&#160;$v=substr($str,$offset,$index-$offset);&#160;&#160;&#160;&#160;$offset=$index+strlen($fstart);&#160;&#160;&#160;&#160;$p=true;&#160;&#160;&#160;&#160;while(($find=substr($str,$offset,strlen($fstart)))==$fstart&#160;&#160;&#160;&#160;&#160;&#160;&#124;&#124;($find=substr($str,$offset,strlen($fend)))==$fend){&#160;&#160;&#160;&#160;&#160;&#160;$v.=$find;&#160;&#160;&#160;&#160;&#160;&#160;$offset=$offset+strlen($find);&#160;&#160;&#160;&#160;&#160;&#160;$p=false;#&#160;如果这个标记是用来转义的&#160;&#160;&#160;&#160;&#160;&#160;if(false!==($index=strpos($str,$fstart,$offset))){&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;$v.=substr($str,$offset,$index-$offset);&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;$offset=$index+strlen($fstart);&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;$p=true;#&#160;查找下一个开始标记&#160;&#160;&#160;&#160;&#160;&#160;}&#160;&#160;&#160;&#160;}&#160;&#160;&#160;&#160;$o.=$v;&#160;&#160;&#160;&#160;$v="";&#160;&#160;&#160;&#160;#&#160;标记了开始&#160;并找到了&#160;结束&#160;&#160;&#160;&#160;while($p&#160;&#160;&#160;&#160;&#160;&#160;&#38;&#38;false!==($end=strpos($str,$fend,$offset))){&#160;&#160;&#160;&#160;&#160;&#160;$v.=substr($str,$offset,$end-$offset);&#160;&#160;&#160;&#160;&#160;&#160;#&#160;如果这个标记是被转义的&#160;&#160;&#160;&#160;&#160;&#160;if(($find=substr($str,$end-strlen($fend),strlen($fstart)))&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;==$fstart){&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;$v=substr($v,0,strlen($v)-strlen($fstart)).$fend;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;$offset=$end+strlen($fend);&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;continue;&#160;&#160;&#160;&#160;&#160;&#160;}&#160;&#160;&#160;&#160;&#160;&#160;$p=false;&#160;&#160;&#160;&#160;}&#160;&#160;&#160;&#160;if($v){&#160;&#160;&#160;&#160;&#160;&#160;if(array_key_exists($v,$maps)){&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;$v=$maps[$v];&#160;&#160;&#160;&#160;&#160;&#160;}else{&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;$v="[".$v."]";&#160;&#160;&#160;&#160;&#160;&#160;}&#160;&#160;&#160;&#160;&#160;&#160;$o.=$v;&#160;&#160;&#160;&#160;&#160;&#160;$offset=$end+strlen($fend);&#160;&#160;&#160;&#160;}&#160;&#160;}&#160;&#160;if($p){&#160;&#160;&#160;&#160;$o.=$fstart;&#160;&#160;}&#160;&#160;$v=substr($str,$offset);&#160;&#160;$o.=$v;&#160;&#160;return&#160;$o;}/**&#160;*&#160;使用maps中定义的value替换对应其key的由标记字符包含的字符串&#160;*&#160;*&#160;如果标记重复出现&#160;则第一个为转义字符（这也意味着标记字符不能作为key的开始字符）&#160;*/function&#160;mapKeysBase($str,$maps,$find=null){&#160;&#160;if(!$find){&#160;&#160;&#160;&#160;$find="%";&#160;&#160;}&#160;&#160;$p=false;&#160;&#160;$v="";&#160;&#160;$index=0;&#160;&#160;$offset=0;&#160;&#160;while(false!==($index=strpos($str,$find,$offset))){&#160;&#160;&#160;&#160;$v.=substr($str,$offset,$index-$offset);&#160;&#160;&#160;&#160;$offset=$index+strlen($find);&#160;&#160;&#160;&#160;while(substr($str,$offset,strlen($find))==$find){&#160;&#160;&#160;&#160;&#160;&#160;$v.=$find;&#160;&#160;&#160;&#160;&#160;&#160;$offset=$offset+strlen($find);&#160;&#160;&#160;&#160;&#160;&#160;if(false!==($index=strpos($str,$find,$offset))){&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;$v.=substr($str,$offset,$index-$offset);&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;$offset=$index+strlen($find);&#160;&#160;&#160;&#160;&#160;&#160;}&#160;&#160;&#160;&#160;}&#160;&#160;&#160;&#160;if($p){&#160;&#160;&#160;&#160;&#160;&#160;if(array_key_exists($v,$maps)){&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;$v=$maps[$v];&#160;&#160;&#160;&#160;&#160;&#160;}else{&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;$v="[".$v."]";&#160;&#160;&#160;&#160;&#160;&#160;}&#160;&#160;&#160;&#160;&#160;&#160;$o.=$v;&#160;&#160;&#160;&#160;&#160;&#160;$v="";&#160;&#160;&#160;&#160;&#160;&#160;$p=false;&#160;&#160;&#160;&#160;}else{&#160;&#160;&#160;&#160;&#160;&#160;$o.=$v;&#160;&#160;&#160;&#160;&#160;&#160;$v="";&#160;&#160;&#160;&#160;&#160;&#160;$p=true;&#160;&#160;&#160;&#160;}&#160;&#160;}&#160;&#160;if($p){&#160;&#160;&#160;&#160;$v.=$find;&#160;&#160;}&#160;&#160;$v.=substr($str,$offset);&#160;&#160;$o.=$v;&#160;&#160;return&#160;$o;}?&#62; 取自&#8221;http://www.fallseir.com/wiki/PHP/MapKeys.html&#8221;]]></description>
			<content:encoded><![CDATA[<p>一段用于替换字符串中指定的key的代码</p>
<p>&#8211;[[User:Fallseir|飞扬轻狂]] 2008年5月6日 (二) 02:32 (PDT)<br />
$str=mapKeys($formatstr,$maps);</p>
<p><span style="color: #0000BB">$str</span><span style="color: #007700">=</span><span style="color: #DD0000">&#8220;replace&nbsp;this&nbsp;template&nbsp;string&nbsp;!the&nbsp;key&nbsp;maps&nbsp;is&nbsp;here<br />key1=&gt;{key1},key{{2=&gt;{key{2},key3}=&gt;{key3{}}&#8221;</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #0000BB">mapKeys</span><span style="color: #007700">(</span><span style="color: #0000BB">$str<br />&nbsp;&nbsp;</span><span style="color: #007700">,array(</span><span style="color: #DD0000">&#8220;key1&#8243;</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">&#8220;value&nbsp;1&#8243;<br />&nbsp;&nbsp;</span><span style="color: #007700">,</span><span style="color: #DD0000">&#8220;key{2&#8243;</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">&#8220;value&nbsp;2&#8243;<br />&nbsp;&nbsp;</span><span style="color: #007700">,</span><span style="color: #DD0000">&#8220;key3}&#8221;</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">&#8220;value&nbsp;3&#8243;<br />&nbsp;&nbsp;</span><span style="color: #007700">)<br />);<br />echo&nbsp;</span><span style="color: #DD0000">&#8220;\n&#8221;</span></p>
<p>output>><br />
replace this template string !the key maps is here<br />
key1=>value 1,key{2=>value 2,key3}=>value 3<br />
abc[the abc value]}}%[%}%%%]%{%[0}%%,%%%,{key],%%,%%[the %value% 2],%%[the %value% 2],%$$%%{,%,<br />
abc%%%%%%%%%,%%%,%key%,%%,%%%key,2%,%,%$$%%,%,</p>
<p>$ php -r &#8216;highlight_file(&#8220;test.php&#8221;);&#8217;</p>
<p><code><span style="color: #000000"><br />
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/**&nbsp;test&nbsp;*/<br /></span><span style="color: #0000BB">$str</span><span style="color: #007700">=</span><span style="color: #DD0000">"replace&nbsp;this&nbsp;template&nbsp;string&nbsp;!the&nbsp;key&nbsp;maps&nbsp;is&nbsp;here<br />key1=&gt;{key1},key{{2=&gt;{key{2},key3}=&gt;{key3{}}"</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #0000BB">mapKeys</span><span style="color: #007700">(</span><span style="color: #0000BB">$str<br />&nbsp;&nbsp;</span><span style="color: #007700">,array(</span><span style="color: #DD0000">"key1"</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">"value&nbsp;1"<br />&nbsp;&nbsp;</span><span style="color: #007700">,</span><span style="color: #DD0000">"key{2"</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">"value&nbsp;2"<br />&nbsp;&nbsp;</span><span style="color: #007700">,</span><span style="color: #DD0000">"key3}"</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">"value&nbsp;3"<br />&nbsp;&nbsp;</span><span style="color: #007700">)<br />);<br />echo&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;</p>
<p></span><span style="color: #0000BB">$str</span><span style="color: #007700">=</span><span style="color: #DD0000">"abc{key}{}}%{%{}%%%}%{{%{0{}%%,%%%,{key},%%,%%{key,2},%%{key,2},%$$%%{,%,"</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #0000BB">mapKeys</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">,array(</span><span style="color: #DD0000">"key"</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">"[the&nbsp;abc&nbsp;value]"<br /></span><span style="color: #007700">,</span><span style="color: #DD0000">"key,2"</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">"[the&nbsp;%value%&nbsp;2]"</span><span style="color: #007700">));<br />echo&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;</p>
<p></span><span style="color: #0000BB">$str</span><span style="color: #007700">=</span><span style="color: #DD0000">"abc%%%%%%%%%,%%%,%key%,%%,%%%key,2%,%,%$$%%,%,"</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #0000BB">mapKeys</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">,array(</span><span style="color: #DD0000">"key"</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">"[the&nbsp;abc&nbsp;value]"<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">,</span><span style="color: #DD0000">"key,2"</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">"[the&nbsp;%value%&nbsp;2]"</span><span style="color: #007700">),</span><span style="color: #DD0000">"|%|"</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #FF8000">//end&nbsp;test*/<br />/*<br />$&nbsp;php&nbsp;test.php<br />output&gt;&gt;<br />replace&nbsp;this&nbsp;template&nbsp;string&nbsp;!the&nbsp;key&nbsp;maps&nbsp;is&nbsp;here<br />key1=&gt;value&nbsp;1,key{2=&gt;value&nbsp;2,key3}=&gt;value&nbsp;3<br />abc[the&nbsp;abc&nbsp;value]}}%[%}%%%]%{%[0}%%,%%%,{key],%%,%%[the&nbsp;%value%&nbsp;2],%%[the&nbsp;%value%&nbsp;2],%$$%%{,%,<br />abc%%%%%%%%%,%%%,%key%,%%,%%%key,2%,%,%$$%%,%,<br />&nbsp;<br />&nbsp;*/<br />&nbsp;<br />&nbsp;<br />/**<br />&nbsp;*&nbsp;使用maps中定义的value替换对应其key的由开始标记字符和结束标记字符包含的字符串<br />&nbsp;*<br />&nbsp;*&nbsp;当标记对外开始标记后跟着开始标记时或结束标记时表示第一个开始标记为转义符<br />&nbsp;*&nbsp;当标记对内开始标记后跟着结束标记时表示第一个开始标记为转义符<br />&nbsp;*&nbsp;末尾没有匹配的开始标记将原样输出<br />&nbsp;*/<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">mapKeys</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">,</span><span style="color: #0000BB">$maps</span><span style="color: #007700">,</span><span style="color: #0000BB">$fstart</span><span style="color: #007700">=</span><span style="color: #0000BB">null</span><span style="color: #007700">,</span><span style="color: #0000BB">$fend</span><span style="color: #007700">=</span><span style="color: #0000BB">null</span><span style="color: #007700">){<br />&nbsp;&nbsp;if(!</span><span style="color: #0000BB">$fstart</span><span style="color: #007700">){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$fstart</span><span style="color: #007700">=</span><span style="color: #DD0000">"{"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$fend</span><span style="color: #007700">=</span><span style="color: #DD0000">"}"</span><span style="color: #007700">;<br />&nbsp;&nbsp;}<br />&nbsp;&nbsp;if(!</span><span style="color: #0000BB">$fend</span><span style="color: #007700">){<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$fend</span><span style="color: #007700">=</span><span style="color: #0000BB">$fstart</span><span style="color: #007700">;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;}<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;如果标记相同则使用mapKeysBase进行替换<br />&nbsp;&nbsp;</span><span style="color: #007700">if(</span><span style="color: #0000BB">$fstart</span><span style="color: #007700">==</span><span style="color: #0000BB">$fend</span><span style="color: #007700">){return&nbsp;</span><span style="color: #0000BB">mapKeysBase</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">,</span><span style="color: #0000BB">$maps</span><span style="color: #007700">,</span><span style="color: #0000BB">$fstart</span><span style="color: #007700">);}<br />&nbsp;<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$index</span><span style="color: #007700">=</span><span style="color: #0000BB">0</span><span style="color: #007700">;<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$offset</span><span style="color: #007700">=</span><span style="color: #0000BB">0</span><span style="color: #007700">;<br />&nbsp;&nbsp;while(</span><span style="color: #0000BB">false</span><span style="color: #007700">!==(</span><span style="color: #0000BB">$index</span><span style="color: #007700">=</span><span style="color: #0000BB">strpos</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">,</span><span style="color: #0000BB">$fstart</span><span style="color: #007700">,</span><span style="color: #0000BB">$offset</span><span style="color: #007700">))){<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">#&nbsp;找到开始标记,处理开始标记之前的数据<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$v</span><span style="color: #007700">=</span><span style="color: #0000BB">substr</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">,</span><span style="color: #0000BB">$offset</span><span style="color: #007700">,</span><span style="color: #0000BB">$index</span><span style="color: #007700">-</span><span style="color: #0000BB">$offset</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$offset</span><span style="color: #007700">=</span><span style="color: #0000BB">$index</span><span style="color: #007700">+</span><span style="color: #0000BB">strlen</span><span style="color: #007700">(</span><span style="color: #0000BB">$fstart</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$p</span><span style="color: #007700">=</span><span style="color: #0000BB">true</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;while((</span><span style="color: #0000BB">$find</span><span style="color: #007700">=</span><span style="color: #0000BB">substr</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">,</span><span style="color: #0000BB">$offset</span><span style="color: #007700">,</span><span style="color: #0000BB">strlen</span><span style="color: #007700">(</span><span style="color: #0000BB">$fstart</span><span style="color: #007700">)))==</span><span style="color: #0000BB">$fstart<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">||(</span><span style="color: #0000BB">$find</span><span style="color: #007700">=</span><span style="color: #0000BB">substr</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">,</span><span style="color: #0000BB">$offset</span><span style="color: #007700">,</span><span style="color: #0000BB">strlen</span><span style="color: #007700">(</span><span style="color: #0000BB">$fend</span><span style="color: #007700">)))==</span><span style="color: #0000BB">$fend</span><span style="color: #007700">){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$v</span><span style="color: #007700">.=</span><span style="color: #0000BB">$find</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$offset</span><span style="color: #007700">=</span><span style="color: #0000BB">$offset</span><span style="color: #007700">+</span><span style="color: #0000BB">strlen</span><span style="color: #007700">(</span><span style="color: #0000BB">$find</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$p</span><span style="color: #007700">=</span><span style="color: #0000BB">false</span><span style="color: #007700">;</span><span style="color: #FF8000">#&nbsp;如果这个标记是用来转义的<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">if(</span><span style="color: #0000BB">false</span><span style="color: #007700">!==(</span><span style="color: #0000BB">$index</span><span style="color: #007700">=</span><span style="color: #0000BB">strpos</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">,</span><span style="color: #0000BB">$fstart</span><span style="color: #007700">,</span><span style="color: #0000BB">$offset</span><span style="color: #007700">))){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$v</span><span style="color: #007700">.=</span><span style="color: #0000BB">substr</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">,</span><span style="color: #0000BB">$offset</span><span style="color: #007700">,</span><span style="color: #0000BB">$index</span><span style="color: #007700">-</span><span style="color: #0000BB">$offset</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$offset</span><span style="color: #007700">=</span><span style="color: #0000BB">$index</span><span style="color: #007700">+</span><span style="color: #0000BB">strlen</span><span style="color: #007700">(</span><span style="color: #0000BB">$fstart</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$p</span><span style="color: #007700">=</span><span style="color: #0000BB">true</span><span style="color: #007700">;</span><span style="color: #FF8000">#&nbsp;查找下一个开始标记<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$o</span><span style="color: #007700">.=</span><span style="color: #0000BB">$v</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$v</span><span style="color: #007700">=</span><span style="color: #DD0000">""</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">#&nbsp;标记了开始&nbsp;并找到了&nbsp;结束<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">while(</span><span style="color: #0000BB">$p<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">&amp;&amp;</span><span style="color: #0000BB">false</span><span style="color: #007700">!==(</span><span style="color: #0000BB">$end</span><span style="color: #007700">=</span><span style="color: #0000BB">strpos</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">,</span><span style="color: #0000BB">$fend</span><span style="color: #007700">,</span><span style="color: #0000BB">$offset</span><span style="color: #007700">))){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$v</span><span style="color: #007700">.=</span><span style="color: #0000BB">substr</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">,</span><span style="color: #0000BB">$offset</span><span style="color: #007700">,</span><span style="color: #0000BB">$end</span><span style="color: #007700">-</span><span style="color: #0000BB">$offset</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">#&nbsp;如果这个标记是被转义的<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">if((</span><span style="color: #0000BB">$find</span><span style="color: #007700">=</span><span style="color: #0000BB">substr</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">,</span><span style="color: #0000BB">$end</span><span style="color: #007700">-</span><span style="color: #0000BB">strlen</span><span style="color: #007700">(</span><span style="color: #0000BB">$fend</span><span style="color: #007700">),</span><span style="color: #0000BB">strlen</span><span style="color: #007700">(</span><span style="color: #0000BB">$fstart</span><span style="color: #007700">)))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;==</span><span style="color: #0000BB">$fstart</span><span style="color: #007700">){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$v</span><span style="color: #007700">=</span><span style="color: #0000BB">substr</span><span style="color: #007700">(</span><span style="color: #0000BB">$v</span><span style="color: #007700">,</span><span style="color: #0000BB">0</span><span style="color: #007700">,</span><span style="color: #0000BB">strlen</span><span style="color: #007700">(</span><span style="color: #0000BB">$v</span><span style="color: #007700">)-</span><span style="color: #0000BB">strlen</span><span style="color: #007700">(</span><span style="color: #0000BB">$fstart</span><span style="color: #007700">)).</span><span style="color: #0000BB">$fend</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$offset</span><span style="color: #007700">=</span><span style="color: #0000BB">$end</span><span style="color: #007700">+</span><span style="color: #0000BB">strlen</span><span style="color: #007700">(</span><span style="color: #0000BB">$fend</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;continue;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$p</span><span style="color: #007700">=</span><span style="color: #0000BB">false</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;if(</span><span style="color: #0000BB">$v</span><span style="color: #007700">){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(</span><span style="color: #0000BB">array_key_exists</span><span style="color: #007700">(</span><span style="color: #0000BB">$v</span><span style="color: #007700">,</span><span style="color: #0000BB">$maps</span><span style="color: #007700">)){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$v</span><span style="color: #007700">=</span><span style="color: #0000BB">$maps</span><span style="color: #007700">[</span><span style="color: #0000BB">$v</span><span style="color: #007700">];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}else{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$v</span><span style="color: #007700">=</span><span style="color: #DD0000">"["</span><span style="color: #007700">.</span><span style="color: #0000BB">$v</span><span style="color: #007700">.</span><span style="color: #DD0000">"]"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$o</span><span style="color: #007700">.=</span><span style="color: #0000BB">$v</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$offset</span><span style="color: #007700">=</span><span style="color: #0000BB">$end</span><span style="color: #007700">+</span><span style="color: #0000BB">strlen</span><span style="color: #007700">(</span><span style="color: #0000BB">$fend</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;}<br />&nbsp;&nbsp;if(</span><span style="color: #0000BB">$p</span><span style="color: #007700">){<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$o</span><span style="color: #007700">.=</span><span style="color: #0000BB">$fstart</span><span style="color: #007700">;<br />&nbsp;&nbsp;}<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$v</span><span style="color: #007700">=</span><span style="color: #0000BB">substr</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">,</span><span style="color: #0000BB">$offset</span><span style="color: #007700">);<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$o</span><span style="color: #007700">.=</span><span style="color: #0000BB">$v</span><span style="color: #007700">;<br />&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">$o</span><span style="color: #007700">;<br />}<br /></span><span style="color: #FF8000">/**<br />&nbsp;*&nbsp;使用maps中定义的value替换对应其key的由标记字符包含的字符串<br />&nbsp;*<br />&nbsp;*&nbsp;如果标记重复出现&nbsp;则第一个为转义字符（这也意味着标记字符不能作为key的开始字符）<br />&nbsp;*/<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">mapKeysBase</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">,</span><span style="color: #0000BB">$maps</span><span style="color: #007700">,</span><span style="color: #0000BB">$find</span><span style="color: #007700">=</span><span style="color: #0000BB">null</span><span style="color: #007700">){<br />&nbsp;&nbsp;if(!</span><span style="color: #0000BB">$find</span><span style="color: #007700">){<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$find</span><span style="color: #007700">=</span><span style="color: #DD0000">"%"</span><span style="color: #007700">;<br />&nbsp;&nbsp;}<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$p</span><span style="color: #007700">=</span><span style="color: #0000BB">false</span><span style="color: #007700">;<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$v</span><span style="color: #007700">=</span><span style="color: #DD0000">""</span><span style="color: #007700">;<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$index</span><span style="color: #007700">=</span><span style="color: #0000BB">0</span><span style="color: #007700">;<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$offset</span><span style="color: #007700">=</span><span style="color: #0000BB">0</span><span style="color: #007700">;<br />&nbsp;&nbsp;while(</span><span style="color: #0000BB">false</span><span style="color: #007700">!==(</span><span style="color: #0000BB">$index</span><span style="color: #007700">=</span><span style="color: #0000BB">strpos</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">,</span><span style="color: #0000BB">$find</span><span style="color: #007700">,</span><span style="color: #0000BB">$offset</span><span style="color: #007700">))){<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$v</span><span style="color: #007700">.=</span><span style="color: #0000BB">substr</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">,</span><span style="color: #0000BB">$offset</span><span style="color: #007700">,</span><span style="color: #0000BB">$index</span><span style="color: #007700">-</span><span style="color: #0000BB">$offset</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$offset</span><span style="color: #007700">=</span><span style="color: #0000BB">$index</span><span style="color: #007700">+</span><span style="color: #0000BB">strlen</span><span style="color: #007700">(</span><span style="color: #0000BB">$find</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;while(</span><span style="color: #0000BB">substr</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">,</span><span style="color: #0000BB">$offset</span><span style="color: #007700">,</span><span style="color: #0000BB">strlen</span><span style="color: #007700">(</span><span style="color: #0000BB">$find</span><span style="color: #007700">))==</span><span style="color: #0000BB">$find</span><span style="color: #007700">){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$v</span><span style="color: #007700">.=</span><span style="color: #0000BB">$find</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$offset</span><span style="color: #007700">=</span><span style="color: #0000BB">$offset</span><span style="color: #007700">+</span><span style="color: #0000BB">strlen</span><span style="color: #007700">(</span><span style="color: #0000BB">$find</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(</span><span style="color: #0000BB">false</span><span style="color: #007700">!==(</span><span style="color: #0000BB">$index</span><span style="color: #007700">=</span><span style="color: #0000BB">strpos</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">,</span><span style="color: #0000BB">$find</span><span style="color: #007700">,</span><span style="color: #0000BB">$offset</span><span style="color: #007700">))){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$v</span><span style="color: #007700">.=</span><span style="color: #0000BB">substr</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">,</span><span style="color: #0000BB">$offset</span><span style="color: #007700">,</span><span style="color: #0000BB">$index</span><span style="color: #007700">-</span><span style="color: #0000BB">$offset</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$offset</span><span style="color: #007700">=</span><span style="color: #0000BB">$index</span><span style="color: #007700">+</span><span style="color: #0000BB">strlen</span><span style="color: #007700">(</span><span style="color: #0000BB">$find</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;if(</span><span style="color: #0000BB">$p</span><span style="color: #007700">){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(</span><span style="color: #0000BB">array_key_exists</span><span style="color: #007700">(</span><span style="color: #0000BB">$v</span><span style="color: #007700">,</span><span style="color: #0000BB">$maps</span><span style="color: #007700">)){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$v</span><span style="color: #007700">=</span><span style="color: #0000BB">$maps</span><span style="color: #007700">[</span><span style="color: #0000BB">$v</span><span style="color: #007700">];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}else{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$v</span><span style="color: #007700">=</span><span style="color: #DD0000">"["</span><span style="color: #007700">.</span><span style="color: #0000BB">$v</span><span style="color: #007700">.</span><span style="color: #DD0000">"]"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$o</span><span style="color: #007700">.=</span><span style="color: #0000BB">$v</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$v</span><span style="color: #007700">=</span><span style="color: #DD0000">""</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$p</span><span style="color: #007700">=</span><span style="color: #0000BB">false</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}else{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$o</span><span style="color: #007700">.=</span><span style="color: #0000BB">$v</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$v</span><span style="color: #007700">=</span><span style="color: #DD0000">""</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$p</span><span style="color: #007700">=</span><span style="color: #0000BB">true</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;}<br />&nbsp;&nbsp;if(</span><span style="color: #0000BB">$p</span><span style="color: #007700">){<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$v</span><span style="color: #007700">.=</span><span style="color: #0000BB">$find</span><span style="color: #007700">;<br />&nbsp;&nbsp;}<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$v</span><span style="color: #007700">.=</span><span style="color: #0000BB">substr</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">,</span><span style="color: #0000BB">$offset</span><span style="color: #007700">);<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$o</span><span style="color: #007700">.=</span><span style="color: #0000BB">$v</span><span style="color: #007700">;<br />&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">$o</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;<br /></span><br /></span><br />
</code></p>
<p>取自&#8221;<a href="http://www.fallseir.com/wiki/PHP/MapKeys.html">http://www.fallseir.com/wiki/PHP/MapKeys.html</a>&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.fallseir.com/2008/05/mapkeys/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
