One to one substitution of the PHP array

time:17-03-25 forum:PHP tools and code
  http://www.cnblogs.com/Zjmainstay/archi... Words.html
the following methods can implement key words and special processing of keywords.

[code].Lt; php
header (.Quot; Content-type: text/html; charset=utf-8.quot;); $search = explode (',','/'.implode ('/ /, / /', $matches.#91; 0.#93;). '/');
/ / / / / no
if (empty ($matches.#91; 0.#93;)) return; Oreach ($replace as $key=.gt; $val) {
if (! Isset ($matches.#91; 0.#93;.#91; $key.#93;)); / / / / / / / > / > merge special replacement array and matching array. Hes.#91; 0.#93;.#91; $i.#93; = isset ($replace.#91; $i.#93;) $replace.#91; $i.#93; $matches.#91; 0.#93;.#91; >; A specific character $tmp_match
$replace = implode (',', $replace);
$replace = str_replace ($word, $tmp_match, $replace); / / / / / / temporary replacement character
$replace = = > = > > > > / > / / / / / / / / / / / / / replacement place G = preg_replace ($search, $replace, $string, 1); / / / / / / / each time only one
$string = str_replace ($tmp_match, $word, $string) in the array is replaced; > $string ='aaabaaacaaadaaa';
$word ='aaa';
$replace = array (null,'xxx','yyy'). Aaab Chinese ccaaad Chinese eee';
$word =' Chinese ';
$replace = array (null, "(replace Chinese 2)', '(replace Chinese 3)');
echo 'Original:'.$string.'.lt; output R / > Original: aaabaaacaaadaaa
output: aaabxxxcyyydaaa

Original: Chinese aaab Chinese ccaaad Chinese eee
output: Chinese aaab (replace Chinese 2) ccaaad (replace Chinese 3) eee
//*/
?.gt;.Gt;

prev:PHP gets and clears all the matching str... next:Henan guy to donate hematopoietic stem c...
post comment
Notice



approved   A rural girl's monologue: what's the...   How the deaf and dumb girls become t...   These old photos of Ji'nan, which ha...   What can you eat for 10 dollars? The...   Through a hundred years, take you to...
rand   For MySQL Illegal mix of collations ...   The difference between gbk_chinese_c...   PHP string intercept function substr...   Snoopy is used to imitate the functi...   PHP class of Snoopy powerful browser...
ads

other

Because all the contents of this site are reproduced from other media, the intention is to provide free services to the public, but it does not mean that this site agrees with its views, and can not be responsible for the authenticity of its verification, such as the copyright unit or individual of the manuscript does not want to publish on this site, please Contact me, I will immediately remove it, thank you. Contact: atseashawk@163.com