|
支持 0
反对 0
举报
2022-03-17 05:29
<?PHP
//seowhy代码用pre标签包围不行吗?不高亮也就算了,排版这么丑……
function changePosition($article) {
preg_match_all('/<tr[^>]*?>.*?<\/tr>/si', $article, $matchs);
if (!$matchs[0]) return $article;
$plus = false;
$replace = '{$line@ME@}';
foreach ($matchs[0] as $k => $v) {
if ($plus) {
$thisid = $k - 1;
$plus = false;
} else {
$thisid = $k + 1;
$plus = true;
}
$curReplace = str_replace('@ME@', $thisid, $replace);
$article = replaceOnce($v, $curReplace, $article);
}
foreach ($matchs[0] as $k => $v) {
$curReplace = str_replace('@ME@', $k, $replace);
$article = str_replace($curReplace, $v, $article);
}
return $article;
}
function replaceOnce($find, $replace, $string) {
$pos = strpos($string, $find);
if ($pos === false) return $string;
$length = strlen($find);
return substr($string, 0, $pos).$($string, $pos + $length);
}
|