1

インターネットでこの機能を見つけましたが、何らかの理由で機能していないようです

function getbetween($content, $start, $end)
{
    $r = explode($start, $content);

    if (isset($r[1]))
    {
        $r = explode($end, $r[1]);
        return $r[0];
    }

    return '';
}

動作していないようです。次のhtmlファイルで試してみました

<test>Hello</test>

これは、値 hello を取得しようとした php ページです。

<?php

include('getbetween.php');
$str = getbetween('test.html','<test>','</test>');
echo $str;

?>

過去に私と一緒に働いたことがありますが、何らかの理由で機能していないようです。

4

3 に答える 3

1

ファイルの実際の内容ではなく、文字列を関数に渡しています。実際のhtmlを渡すためにこれを試してください。

<?php

include('getbetween.php');
$str = getbetween(file_get_contents('test.html'),'<test>','</test>');
echo $str;
于 2013-04-30T17:26:58.223 に答える