【发布时间】:2018-01-02 03:08:34
【问题描述】:
我在兜圈子。我想在字符串中搜索 span 标签,然后将其替换为备用版本,最后打印所有更改的列表。
我希望这有助于向某人展示我正在尝试做什么...喜欢挑战吗?
// create array to hold tooltips
$tips = array();
// search $content string and add all matching strings to $tips array
$haystack = $content;
$needle = '<span class="has-tip">['.ADD THIS TO $tips ARRAY.']</span>';
// print $content and string replace as such...
$replace = '<span class="has-tip">['.$tips[$i].']</span>';
$with = '<a href="#_ftn'.$i.'" name="_ftnref'.$i.'"><span data-tooltip aria-haspopup="true" class="has-tip top" data-disable-hover="false" tabindex="'.$i.'" title="'.$tips[$i].'">['.$i.']</span></a>';
print $content;
// list all tooltips
echo '<ul>';
foreach ($tips as $key => $tip) {
echo '<li><a href="#_ftnref'.$key.'" name="_ftn'.$key.'">['.$key.']</a> '.$tip.'</li>';
}
echo '<ul>';
【问题讨论】:
-
也许如果您能向我们展示数据——原始输入和所需输出——我们可以帮助编写代码。
-
有什么帮助吗?
-
对不起,我没有时间写答案,但以下内容应该可以帮助您开始解决这个问题。 stackoverflow.com/questions/18858493/…stackoverflow.com/questions/7038065/dom-change-element-content
标签: php preg-replace