0

このテキストがあるとします:

アロンはメリバで兄弟の罪に関与していた(民数記20:8-13 )ため、約束の地に入ることが許されませんでした。部族が「エドムの地の端」にあるホル山に到着したとき、神の命令でモーセはアロンとその息子エレアザルをその山の頂上に導きました。そこで彼はアロンから祭服を剥ぎ取り、それをエレアザルに着せた。そしてそこでアロンは山の頂上で死に、123 歳になった (民数記20:23-29 . Comp. Deut. 10:6 ; 32:50 )

私がやりたいことは、上記のすべての太字のテキストを link に変換することです。

  • 番号。20:8-12 は次のようになります: < a href="num20.8-12">Num. 20:8-13< /a>
  • 申命記 10:6; 32:50 のようになります: < a href="deut10.6">Deut. 10:6< /a> < a href="deut32.50">申命記。32:50< /a>

このテキストの構成は次のようになります。

<DIV>
  <B>Aaron</B>
  <SPAN>
    Aaron was implicated in the sin of his brother at Meribah (Num. 20:8-13), and on that account was not permitted to enter the Promised Land. When the tribes arrived at Mount Hor, "in the edge of the land of Edom," at the command of God Moses led Aaron and his son Eleazar to the top of that mountain, in the sight of all the people. There he stripped Aaron of his priestly vestments, and put them upon Eleazar; and there Aaron died on the top of the mount, being 123 years old (Num. 20:23-29. Comp. Deut. 10:6; 32:50)
  </SPAN>
</DIV>

素晴らしいアイデアをいただければ幸いです。ありがとう :)


編集

コード:

$chapters = array ("Deut", "Num");

$html = file_get_html($link);

foreach($html->find('div') as $dict) {
    $descr  = $dict->find('SPAN', 0)->innertext;    
    $descrl = preg_replace("/$chapters\. [0-9:-]*/", "<a href=\"$0\">$0</a>", $descr); //--> See description below

    echo $descrl . "<hr/>";
}

説明: をまたはの$chaptersような 1 つの単語に変更するとうまくいきますが、 に変更するとリンクが返されません。NumDeut$chapters

4

1 に答える 1

2

自分で定義して改善する必要があるルールを指定しませんでした。私はあなたの特定のケースを処理しました。

//replace against either book followed by period followed by space
//followed by one or more digit, comma, semicolon, space, or dash
txt.replace(/(Num|Deut)\. ([\d:,; -]+)/g, function (match, book, verses) {
    var link = '';
    //split the verse on semicolon + space as each must be linked
    verses.split(/;\s+/).forEach(function (elem) {
        //create the link; replace : with period
        link += '<a href="' + book.toLowerCase() + elem.replace(':', '.') + '">'
            + book + '. ' + elem + '</a> ';
    });
    return link;
});

http://jsfiddle.net/XaVXW/

于 2013-03-29T03:48:58.943 に答える