Exemple #1
0
function extract_tags($Html, $Begin, $End, $Separator = '', $Contain1 = null, $Contain2 = null, $Contain3 = null)
{
    $Result = array();
    $Begin = prepare_ereg_param($Begin);
    $BArr = spliti($Begin, $Html);
    $i = 0;
    foreach ($BArr as $s) {
        if ($i > 0) {
            $PSE = stripos($s, $End);
            if ($PSE === false) {
                continue;
            }
            $RSt = substr($s, 0, $PSE);
            if ($Contain1) {
                $PSC1 = stripos($RSt, $Contain1);
                if ($PSC1 === false) {
                    continue;
                }
                if ($Contain2) {
                    $PSC2 = stripos($RSt, $Contain2, $PSC1 + strlen($Contain1));
                    if ($PSC2 === false) {
                        continue;
                    }
                    if ($Contain3) {
                        $PSC3 = stripos($RSt, $Contain3, $PSC2 + strlen($Contain2));
                        if ($PSC3 === false) {
                            continue;
                        }
                    }
                }
            }
            $Result[] = $Begin . $RSt . $End;
        }
        $i++;
    }
    if (count($Result) > 0) {
        return implode($Separator, $Result);
    } else {
        return null;
    }
}
Exemple #2
0
function numbering_tag_count($Html, $TagName, &$TagNo)
{
    $TagNo = 0;
    $Begin = prepare_ereg_param("<{$TagName}");
    $End = prepare_ereg_param("</{$TagName}");
    do {
        $BArr = null;
        $BArr = spliti($Begin, $Html);
        if (count($BArr) == 1) {
            break;
        }
        for ($i = 1, $m = count($BArr); $i < $m; $i++) {
            $s = $BArr[$i];
            if ($s[0] != ' ' and $s[0] != '>') {
                continue;
            }
            $PSE = stripos($s, $End);
            if ($PSE === false) {
                continue;
            }
            $TagNo++;
            $TagNoProp = "\tTagNo=\"{$TagName}{$TagNo}\"";
            $EArr = spliti("</{$TagName}", $s);
            if (count($EArr) > 1) {
                $EArr[1] = $TagNoProp . $EArr[1];
            }
            $BArr[$i] = $TagNoProp . implode($End, $EArr);
        }
        $Html = implode($Begin, $BArr);
        $Html = str_ireplace("<{$TagName}\t", "<|{$TagName}\t", $Html);
        $Html = str_ireplace("</{$TagName}\t", "<|/{$TagName}\t", $Html);
    } while (true);
    $Html = str_ireplace("<|{$TagName}\t", "<{$TagName}\t", $Html);
    $Html = str_ireplace("<|/{$TagName}\t", "</{$TagName}\t", $Html);
    return $Html;
}