preg_replace单词 [英] preg_replace words
本文介绍了preg_replace单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
只需尝试使用&span class ="brc"&word;</span>
来包含某些 td 元素的innerWords.
Just trying to embrace the innerWords of some td-elements with <span class="brc">Words</span>
.
<td class="views-field views-field-summoner-name-1"> Zeit für ein dududuDUELL </td>
<td class="views-field views-field-summoner-name-1"> EloDrop </td>
<td class="views-field views-field-summoner-name-1"> HighPINGklärtGG </td>
<td class="views-field views-field-summoner-name-1"> BlaViShi </td>
<td class="views-field views-field-summoner-name-1"> Bruteforce tv </td>
td类 views-field 不能用于它.我当前的代码是:
The td-class views-field cant't be used for it. My current codes is:
<?php
$url = "http://competitive.euw.leagueoflegends.com/de/ladders/euw/current/ranked_team_3x3";
preg_match('#<table class="views-table cols-6"[^>]+>[\w\W]*?</table>#i', file_get_contents($url), $match);
echo $match[0];
$brc = array("Zeit für ein dududuDUELL","OP Scheisse","Selbstzerstörungsknopf","EloDrop","HighPINGklärtGG","BlaViShi");
echo preg_replace(I dont know how this works);
?>
推荐答案
如果 $ brc
是要用 span
换行的字符串数组,则可以循环遍历它们并使用 str_replace
:
If $brc
is an array of strings you want to wrap with the span
you could loop through them and use str_replace
:
foreach($brc as $str) {
$match[0] = str_replace($str, '<span class="brc">'.$str.'</span>', $match[0]);
}
这篇关于preg_replace单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文