I’m trying to figure out:
preg_match_all("(?<=\\<div style=\\"direction:rtl\\">).*(?=\\</div>)", $file, $content);
I want the innerHTML of a div tag which has the style direction: rtl.
It’s giving me this warning:
Warning: preg_match_all() [function.preg-match-all]: Unknown modifier ‘.’ in C:\…\index.php on line 42
joebert:
If there’s any chance at all of there being a <div> element inside of the one you’re targeting, using preg_match_all isn’t going to work. Reason being there’s no way to track the opening and closing of a dynamic number of elements with a single pattern, so it will wrongly end the match on the inner <div> elements closing tag.
<div id="targeted"><h1>text</h1><div class="container">...</div></div>
Instead, you’ll want to use simplexml and xpath.
http://www.php.net/manual/en/simplexmlelement.xpath.php
–
It looks like the reason you’re getting an error in your regular expression, is that you’ve not used a good delimiter around your pattern. It seems to be matching the opening parenthesis your pattern starts with to the first instance of a closing parenthesis, which makes the engine believe your pattern stops there and when it comes across that dot it’s expecting a pattern modifier and the dot isn’t a valid modifier. If you take that dot out, it will probably give you the same error about the next character in the pattern.
How about getting the hebrew out of this:
<div style="direction:rtl"><span class="reftext"><a href="http://biblos.com/genesis/1-1.htm"><b>1</b></a></span> בְּרֵאשִׁ֖ית בָּרָ֣א אֱלֹהִ֑ים אֵ֥ת הַשָּׁמַ֖יִם וְאֵ֥ת הָאָֽרֶץ׃
<span class="reftext"><a href="http://biblos.com/genesis/1-2.htm"><b>2</b></a></span> וְהָאָ֗רֶץ הָיְתָ֥ה תֹ֙הוּ֙ וָבֹ֔הוּ וְחֹ֖שֶׁךְ עַל־פְּנֵ֣י תְהֹ֑ום וְר֣וּחַ אֱלֹהִ֔ים מְרַחֶ֖פֶת עַל־פְּנֵ֥י הַמָּֽיִם׃
<span class="reftext"><a href="http://biblos.com/genesis/1-3.htm"><b>3</b></a></span> וַיֹּ֥אמֶר אֱלֹהִ֖ים יְהִ֣י אֹ֑ור וַֽיְהִי־אֹֽור׃
<span class="reftext"><a href="http://biblos.com/genesis/1-4.htm"><b>4</b></a></span> וַיַּ֧רְא אֱלֹהִ֛ים אֶת־הָאֹ֖ור כִּי־טֹ֑וב וַיַּבְדֵּ֣ל אֱלֹהִ֔ים בֵּ֥ין הָאֹ֖ור וּבֵ֥ין הַחֹֽשֶׁךְ׃
<span class="reftext"><a href="http://biblos.com/genesis/1-5.htm"><b>5</b></a></span> וַיִּקְרָ֨א אֱלֹהִ֤ים ׀ לָאֹור֙ יֹ֔ום וְלַחֹ֖שֶׁךְ קָ֣רָא לָ֑יְלָה וַֽיְהִי־עֶ֥רֶב וַֽיְהִי־בֹ֖קֶר יֹ֥ום אֶחָֽד׃ פ<p>
<span class="reftext"><a href="http://biblos.com/genesis/1-6.htm"><b>6</b></a></span> וַיֹּ֣אמֶר אֱלֹהִ֔ים יְהִ֥י רָקִ֖יעַ בְּתֹ֣וךְ הַמָּ֑יִם וִיהִ֣י מַבְדִּ֔יל בֵּ֥ין מַ֖יִם לָמָֽיִם׃
<span class="reftext"><a href="http://biblos.com/genesis/1-7.htm"><b>7</b></a></span> וַיַּ֣עַשׂ אֱלֹהִים֮ אֶת־הָרָקִיעַ֒ וַיַּבְדֵּ֗ל בֵּ֤ין הַמַּ֙יִם֙ אֲשֶׁר֙ מִתַּ֣חַת לָרָקִ֔יעַ וּבֵ֣ין הַמַּ֔יִם אֲשֶׁ֖ר מֵעַ֣ל לָרָקִ֑יעַ וַֽיְהִי־כֵֽן׃
<span class="reftext"><a href="http://biblos.com/genesis/1-8.htm"><b>8</b></a></span> וַיִּקְרָ֧א אֱלֹהִ֛ים לָֽרָקִ֖יעַ שָׁמָ֑יִם וַֽיְהִי־עֶ֥רֶב וַֽיְהִי־בֹ֖קֶר יֹ֥ום שֵׁנִֽי׃ פ<p>
<span class="reftext"><a href="http://biblos.com/genesis/1-9.htm"><b>9</b></a></span> וַיֹּ֣אמֶר אֱלֹהִ֗ים יִקָּו֨וּ הַמַּ֜יִם מִתַּ֤חַת הַשָּׁמַ֙יִם֙ אֶל־מָקֹ֣ום אֶחָ֔ד וְתֵרָאֶ֖ה הַיַּבָּשָׁ֑ה וַֽיְהִי־כֵֽן׃
<span class="reftext"><a href="http://biblos.com/genesis/1-10.htm"><b>10</b></a></span> וַיִּקְרָ֨א אֱלֹהִ֤ים ׀ לַיַּבָּשָׁה֙ אֶ֔רֶץ וּלְמִקְוֵ֥ה הַמַּ֖יִם קָרָ֣א יַמִּ֑ים וַיַּ֥רְא אֱלֹהִ֖ים כִּי־טֹֽוב׃
<span class="reftext"><a href="http://biblos.com/genesis/1-11.htm"><b>11</b></a></span> וַיֹּ֣אמֶר אֱלֹהִ֗ים תַּֽדְשֵׁ֤א הָאָ֙רֶץ֙ דֶּ֔שֶׁא עֵ֚שֶׂב מַזְרִ֣יעַ זֶ֔רַע עֵ֣ץ פְּרִ֞י עֹ֤שֶׂה פְּרִי֙ לְמִינֹ֔ו אֲשֶׁ֥ר זַרְעֹו־בֹ֖ו עַל־הָאָ֑רֶץ וַֽיְהִי־כֵֽן׃
<span class="reftext"><a href="http://biblos.com/genesis/1-12.htm"><b>12</b></a></span> וַתֹּוצֵ֨א הָאָ֜רֶץ דֶּ֠שֶׁא עֵ֣שֶׂב מַזְרִ֤יעַ זֶ֙רַע֙ לְמִינֵ֔הוּ וְעֵ֧ץ עֹֽשֶׂה־פְּרִ֛י אֲשֶׁ֥ר זַרְעֹו־בֹ֖ו לְמִינֵ֑הוּ וַיַּ֥רְא אֱלֹהִ֖ים כִּי־טֹֽוב׃
<span class="reftext"><a href="http://biblos.com/genesis/1-13.htm"><b>13</b></a></span> וַֽיְהִי־עֶ֥רֶב וַֽיְהִי־בֹ֖קֶר יֹ֥ום שְׁלִישִֽׁי׃ פ<p>
<span class="reftext"><a href="http://biblos.com/genesis/1-14.htm"><b>14</b></a></span> וַיֹּ֣אמֶר אֱלֹהִ֗ים יְהִ֤י מְאֹרֹת֙ בִּרְקִ֣יעַ הַשָּׁמַ֔יִם לְהַבְדִּ֕יל בֵּ֥ין הַיֹּ֖ום וּבֵ֣ין הַלָּ֑יְלָה וְהָי֤וּ לְאֹתֹת֙ וּלְמֹ֣ועֲדִ֔ים וּלְיָמִ֖ים וְשָׁנִֽים׃
<span class="reftext"><a href="http://biblos.com/genesis/1-15.htm"><b>15</b></a></span> וְהָי֤וּ לִמְאֹורֹת֙ בִּרְקִ֣יעַ הַשָּׁמַ֔יִם לְהָאִ֖יר עַל־הָאָ֑רֶץ וַֽיְהִי־כֵֽן׃
<span class="reftext"><a href="http://biblos.com/genesis/1-16.htm"><b>16</b></a></span> וַיַּ֣עַשׂ אֱלֹהִ֔ים אֶת־שְׁנֵ֥י הַמְּאֹרֹ֖ת הַגְּדֹלִ֑ים אֶת־הַמָּאֹ֤ור הַגָּדֹל֙ לְמֶמְשֶׁ֣לֶת הַיֹּ֔ום וְאֶת־הַמָּאֹ֤ור הַקָּטֹן֙ לְמֶמְשֶׁ֣לֶת הַלַּ֔יְלָה וְאֵ֖ת הַכֹּוכָבִֽים׃
<span class="reftext"><a href="http://biblos.com/genesis/1-17.htm"><b>17</b></a></span> וַיִּתֵּ֥ן אֹתָ֛ם אֱלֹהִ֖ים בִּרְקִ֣יעַ הַשָּׁמָ֑יִם לְהָאִ֖יר עַל־הָאָֽרֶץ׃
<span class="reftext"><a href="http://biblos.com/genesis/1-18.htm"><b>18</b></a></span> וְלִמְשֹׁל֙ בַּיֹּ֣ום וּבַלַּ֔יְלָה וּֽלֲהַבְדִּ֔יל בֵּ֥ין הָאֹ֖ור וּבֵ֣ין הַחֹ֑שֶׁךְ וַיַּ֥רְא אֱלֹהִ֖ים כִּי־טֹֽוב׃
<span class="reftext"><a href="http://biblos.com/genesis/1-19.htm"><b>19</b></a></span> וַֽיְהִי־עֶ֥רֶב וַֽיְהִי־בֹ֖קֶר יֹ֥ום רְבִיעִֽי׃ פ<p>
<span class="reftext"><a href="http://biblos.com/genesis/1-20.htm"><b>20</b></a></span> וַיֹּ֣אמֶר אֱלֹהִ֔ים יִשְׁרְצ֣וּ הַמַּ֔יִם שֶׁ֖רֶץ נֶ֣פֶשׁ חַיָּ֑ה וְעֹוף֙ יְעֹופֵ֣ף עַל־הָאָ֔רֶץ עַל־פְּנֵ֖י רְקִ֥יעַ הַשָּׁמָֽיִם׃
<span class="reftext"><a href="http://biblos.com/genesis/1-21.htm"><b>21</b></a></span> וַיִּבְרָ֣א אֱלֹהִ֔ים אֶת־הַתַּנִּינִ֖ם הַגְּדֹלִ֑ים וְאֵ֣ת כָּל־נֶ֣פֶשׁ הַֽחַיָּ֣ה ׀ הָֽרֹמֶ֡שֶׂת אֲשֶׁר֩ שָׁרְצ֨וּ הַמַּ֜יִם לְמִֽינֵהֶ֗ם וְאֵ֨ת כָּל־עֹ֤וף כָּנָף֙ לְמִינֵ֔הוּ וַיַּ֥רְא אֱלֹהִ֖ים כִּי־טֹֽוב׃
<span class="reftext"><a href="http://biblos.com/genesis/1-22.htm"><b>22</b></a></span> וַיְבָ֧רֶךְ אֹתָ֛ם אֱלֹהִ֖ים לֵאמֹ֑ר פְּר֣וּ וּרְב֗וּ וּמִלְא֤וּ אֶת־הַמַּ֙יִם֙ בַּיַּמִּ֔ים וְהָעֹ֖וף יִ֥רֶב בָּאָֽרֶץ׃
<span class="reftext"><a href="http://biblos.com/genesis/1-23.htm"><b>23</b></a></span> וַֽיְהִי־עֶ֥רֶב וַֽיְהִי־בֹ֖קֶר יֹ֥ום חֲמִישִֽׁי׃ פ<p>
<span class="reftext"><a href="http://biblos.com/genesis/1-24.htm"><b>24</b></a></span> וַיֹּ֣אמֶר אֱלֹהִ֗ים תֹּוצֵ֨א הָאָ֜רֶץ נֶ֤פֶשׁ חַיָּה֙ לְמִינָ֔הּ בְּהֵמָ֥ה וָרֶ֛מֶשׂ וְחַֽיְתֹו־אֶ֖רֶץ לְמִינָ֑הּ וַֽיְהִי־כֵֽן׃
<span class="reftext"><a href="http://biblos.com/genesis/1-25.htm"><b>25</b></a></span> וַיַּ֣עַשׂ אֱלֹהִים֩ אֶת־חַיַּ֨ת הָאָ֜רֶץ לְמִינָ֗הּ וְאֶת־הַבְּהֵמָה֙ לְמִינָ֔הּ וְאֵ֛ת כָּל־רֶ֥מֶשׂ הָֽאֲדָמָ֖ה לְמִינֵ֑הוּ וַיַּ֥רְא אֱלֹהִ֖ים כִּי־טֹֽוב׃<p>
<span class="reftext"><a href="http://biblos.com/genesis/1-26.htm"><b>26</b></a></span> וַיֹּ֣אמֶר אֱלֹהִ֔ים נַֽעֲשֶׂ֥ה אָדָ֛ם בְּצַלְמֵ֖נוּ כִּדְמוּתֵ֑נוּ וְיִרְדּוּ֩ בִדְגַ֨ת הַיָּ֜ם וּבְעֹ֣וף הַשָּׁמַ֗יִם וּבַבְּהֵמָה֙ וּבְכָל־הָאָ֔רֶץ וּבְכָל־הָרֶ֖מֶשׂ הָֽרֹמֵ֥שׂ עַל־הָאָֽרֶץ׃
<span class="reftext"><a href="http://biblos.com/genesis/1-27.htm"><b>27</b></a></span> וַיִּבְרָ֨א אֱלֹהִ֤ים ׀ אֶת־הָֽאָדָם֙ בְּצַלְמֹ֔ו בְּצֶ֥לֶם אֱלֹהִ֖ים בָּרָ֣א אֹתֹ֑ו זָכָ֥ר וּנְקֵבָ֖ה בָּרָ֥א אֹתָֽם׃
<span class="reftext"><a href="http://biblos.com/genesis/1-28.htm"><b>28</b></a></span> וַיְבָ֣רֶךְ אֹתָם֮ אֱלֹהִים֒ וַיֹּ֨אמֶר לָהֶ֜ם אֱלֹהִ֗ים פְּר֥וּ וּרְב֛וּ וּמִלְא֥וּ אֶת־הָאָ֖רֶץ וְכִבְשֻׁ֑הָ וּרְד֞וּ בִּדְגַ֤ת הַיָּם֙ וּבְעֹ֣וף הַשָּׁמַ֔יִם וּבְכָל־חַיָּ֖ה הָֽרֹמֶ֥שֶׂת עַל־הָאָֽרֶץ׃
<span class="reftext"><a href="http://biblos.com/genesis/1-29.htm"><b>29</b></a></span> וַיֹּ֣אמֶר אֱלֹהִ֗ים הִנֵּה֩ נָתַ֨תִּי לָכֶ֜ם אֶת־כָּל־עֵ֣שֶׂב ׀ זֹרֵ֣עַ זֶ֗רַע אֲשֶׁר֙ עַל־פְּנֵ֣י כָל־הָאָ֔רֶץ וְאֶת־כָּל־הָעֵ֛ץ אֲשֶׁר־בֹּ֥ו פְרִי־עֵ֖ץ זֹרֵ֣עַ זָ֑רַע לָכֶ֥ם יִֽהְיֶ֖ה לְאָכְלָֽה׃
<span class="reftext"><a href="http://biblos.com/genesis/1-30.htm"><b>30</b></a></span> וּֽלְכָל־חַיַּ֣ת הָ֠אָרֶץ וּלְכָל־עֹ֨וף הַשָּׁמַ֜יִם וּלְכֹ֣ל ׀ רֹומֵ֣שׂ עַל־הָאָ֗רֶץ אֲשֶׁר־בֹּו֙ נֶ֣פֶשׁ חַיָּ֔ה אֶת־כָּל־יֶ֥רֶק עֵ֖שֶׂב לְאָכְלָ֑ה וַֽיְהִי־כֵֽן׃
<span class="reftext"><a href="http://biblos.com/genesis/1-31.htm"><b>31</b></a></span> וַיַּ֤רְא אֱלֹהִים֙ אֶת־כָּל־אֲשֶׁ֣ר עָשָׂ֔ה וְהִנֵּה־טֹ֖וב מְאֹ֑ד וַֽיְהִי־עֶ֥רֶב וַֽיְהִי־בֹ֖קֶר יֹ֥ום הַשִּׁשִּֽׁי׃ פ<p></div>
If there’s any chance at all of there being a <div> element inside of the one you’re targeting, using preg_match_all isn’t going to work. Reason being there’s no way to track the opening and closing of a dynamic number of elements with a single pattern, so it will wrongly end the match on the inner <div> elements closing tag.
<div id="targeted"><h1>text</h1><div class="container">...</div></div>
Instead, you’ll want to use simplexml and xpath.
http://www.php.net/manual/en/simplexmlelement.xpath.php
–
It looks like the reason you’re getting an error in your regular expression, is that you’ve not used a good delimiter around your pattern. It seems to be matching the opening parenthesis your pattern starts with to the first instance of a closing parenthesis, which makes the engine believe your pattern stops there and when it comes across that dot it’s expecting a pattern modifier and the dot isn’t a valid modifier. If you take that dot out, it will probably give you the same error about the next character in the pattern.
I also want preg_match_all to pick up all the hebrew in this:
<span class="reftext"><a href="http://biblos.com/genesis/1-31.htm"><b>31</b></a></span> וַיַּ֤רְא אֱלֹהִים֙ אֶת־כָּל־אֲשֶׁ֣ר עָשָׂ֔ה וְהִנֵּה־טֹ֖וב מְאֹ֑ד וַֽיְהִי־עֶ֥רֶב וַֽיְהִי־בֹ֖קֶר יֹ֥ום הַשִּׁשִּֽׁי׃ פ<p>
It’s found outside of any tags but can there be any regex made out of and <p> ?