久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長(zhǎng)資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      php如何進(jìn)行字符串匹配替換

      php字符串匹配替換的方法:執(zhí)行一個(gè)正則表達(dá)式搜索并且使用一個(gè)回調(diào)進(jìn)行替換,代碼為【preg_replace_callback()return preg_replace_callback('/\{([w-/]+)\}/'】。

      php如何進(jìn)行字符串匹配替換

      php字符串匹配替換的方法:

       <?php     $templ = "{username}是個(gè)大{adj}比{end}";//測(cè)試字符串     //對(duì)應(yīng)數(shù)據(jù)     $datas = [         'username' => '我',         'adj' => '帥',         'end' => '。',     ];     //不需要替換的字符串     $noMatchs = ['end'];     function render($datas = array(), $templ = '', $noMatchs = array()) {             //preg_replace_callback()             //執(zhí)行一個(gè)正則表達(dá)式搜索并且使用一個(gè)回調(diào)進(jìn)行替換             return  preg_replace_callback('/\{([w-/]+)\}/', function ($matches) use ($datas, $noMatchs) {                 //$matches[1]返回如:username                 $name = $matches[1];                 if (in_array($name, $noMatchs)) {                     //$mathches[0]返回如:{end}                     return $matches[0];                 }                 return array_key_exists($name, $datas) ? $datas[$name] : '';             }, $templ);         }     var_dump(render($datas, $templ, $noMatchs));     //輸出結(jié)果為:'我是個(gè)大帥比{end}'

      相關(guān)免費(fèi)學(xué)習(xí)推薦:php編程(視頻)

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)