php str_ireplace

<p>str_ireplace</p><p>(PHP 5)</p><p>str_ireplace -- Case-insensitive version of str_replace().</p><p>Description</p><p>mixed str_ireplace ( mixed search, mixed replace, mixed subject [, int &amp;count] )</p><p>This function returns a string or an array with all occurrences of search in subject (ignoring case) replaced with the given replace value. If you don&#39;t need fancy replacing rules, you should generally use this function instead oferegi_replace() or preg_replace() with the i modifier.</p><p>If subject is an array, then the search and replace is performed with every entry of subject, and the return value is an array as well.</p><p>If search and replace are arrays, then str_ireplace() takes a value from each array and uses them to do search and replace on subject. If replace has fewer values than search, then an empty string is used for the rest of replacement values. If search is an array and replace is a string; then this replacement string is used for every value of search.</p><p>例子 1. str_ireplace() example</p><pre class="brush:php;toolbar:false">&lt;?php $bodytag=str_ireplace(&quot;%body%&quot;,&quot;black&quot;,&quot;&lt;bodytext=%BODY%&gt;&quot;); ?&gt; if(!function_exists(&#39;str_ireplace&#39;)){ functionstr_ireplace($search,$replacement,$string){ $delimiters=array(1,2,3,4,5,6,7,8,14,15,16,17,18,19,20,21,22,23,24,25, 26,27,28,29,30,31,33,247,215,191,190,189,188,187,186, 185,184,183,182,180,177,176,175,174,173,172,171,169, 168,167,166,165,164,163,162,161,157,155,153,152,151, 150,149,148,147,146,145,144,143,141,139,137,136,135, 134,133,132,130,129,128,127,126,125,124,123,96,95,94, 63,62,61,60,59,58,47,46,45,44,38,37,36,35,34); foreach($delimitersas$d){ if(strpos($string,chr($d))===false){ $delimiter=chr($d); break; } } if(!empty($delimiter)){ returnpreg_replace($delimiter.quotemeta($search).$delimiter.&#39;i&#39;,$replacement,$string); } else{ trigger_error(&#39;Homemadestr_ireplacecouldnotfindaproperdelimiter.&#39;,E_USER_ERROR); } } }</pre>
RangeTime:0.009737s
RangeMem:205.52 KB
返回顶部 留言