1. We need a regular expression to split the html content into multiple pages (for pagination) and store them in PHP array. (please check the html example bellow)
The end of the "page" is described with the following tag: <hr class=”some-pagebreak” />
The RegEx should find this tags and return the HTML "page sections" into a PHP array.
2. Regular expression to extract a section of text from a tag. The Regexes is needed in Javascript and PHP.
This is the sample scenario where we require the Regex to work:
Javascript:
- Function to wrap selected html in the following tag: ‘<span class=”pragma-teaser”>’ and ‘</span>’. Please check the html example bellow.
- CONDITION: There should be only one paragraph that is embedded in the above mentioned span tag . We need another Regex function that will search for an instance of this tag and if it finds it it should remove it from that paragraph an apply it to the selected html.
- We also need Regex for stripping the ‘<span class=”pragma-teaser”>’ and ‘</span>’ tags if we want to remove teaser. So we need another RegEx that will remove this tag and leave the inner HTML untouched.
- PHP:
Extract the html content contained in ‘<p class=”pragma-teaser”>’ and ‘</p>’ for
Remove ‘<p class=”pragma-teaser”>’ and ‘</p>’ when displaying the full article
html EXAMPLE
var html = '<h2><span class="editsection">[<a href="/w/[login to view URL];amp;action=edit&amp;section=5" title="Edit section: Equipment">edit</a>]</span> <span class="mw-headline">Equipment</span></h2>
<div class="rellink boilerplate seealso">See also: <a href="/wiki/Lightsaber" title="Lightsaber">Lightsaber</a></div>
<p>Within the Star Wars universe, the Jedi are usually portrayed as dressed in simple robes and carrying specialized field gear for their missions. The most notable instrument wielded by a Jedi is the <a href="/wiki/Lightsaber" title="Lightsaber">lightsaber</a>.</p>
<p>Lightsabers are used by both Jedi and Sith. Jedi commonly wield blue and green lightsabers in the movies, while the Sith tend to wield red ones. Jedi <a href="/wiki/Mace_Windu" title="Mace Windu">Mace Windu</a> (<a href="/wiki/Samuel_L._Jackson" title="Samuel L. Jackson">Samuel L. Jackson</a>) and Siri Tachi (from Expanded Universe books) wield unique purple lightsabers. Master Yaddle was known to wield an orange lightsaber. The former Jedi Padawan Ferus Olin, from Expanded Universe books, wielded a red blade. However, he was not a <a href="/wiki/Sith" title="Sith">Sith</a>.</p>
<p>In the Expanded Universe of Star Wars media, there were a vast variety of lightsaber colors. In <i><a href="/wiki/Star_Wars:_Knights_of_the_Old_Republic" title="Star Wars: Knights of the Old Republic">Knights of the Old Republic</a></i> video game, the colors signified the Jedi's specialization.</p>
<p><br /></p>’;
var text = ‘Within the Star Wars universe, the Jedi are usually portrayed as dressed in simple robes and carrying specialized field gear for their missions. The most notable instrument wielded by a Jedi is the <a href="/wiki/Lightsaber" title="Lightsaber">lightsaber</a>.';
After replace:
html = '<h2><span class="editsection">[<a href="/w/[login to view URL];amp;action=edit&amp;section=5" title="Edit section: Equipment">edit</a>]</span> <span class="mw-headline">Equipment</span></h2>
<div class="rellink boilerplate seealso">See also: <a href="/wiki/Lightsaber" title="Lightsaber">Lightsaber</a></div>
<p><span class=”pragma-meta”>Within the Star Wars universe, the Jedi are usually portrayed as dressed in simple robes and carrying specialized field gear for their missions. The most notable instrument wielded by a Jedi is the <a href="/wiki/Lightsaber" title="Lightsaber">lightsaber</a>.</span></p>
<p>Lightsabers are used by both Jedi and Sith. Jedi commonly wield blue and green lightsabers in the movies, while the Sith tend to wield red ones. Jedi <a href="/wiki/Mace_Windu" title="Mace Windu">Mace Windu</a> (<a href="/wiki/Samuel_L._Jackson" title="Samuel L. Jackson">Samuel L. Jackson</a>) and Siri Tachi (from Expanded Universe books) wield unique purple lightsabers. Master Yaddle was known to wield an orange lightsaber. The former Jedi Padawan Ferus Olin, from Expanded Universe books, wielded a red blade. However, he was not a <a href="/wiki/Sith" title="Sith">Sith</a>.</p>
<p>In the Expanded Universe of Star Wars media, there were a vast variety of lightsaber colors. In <i><a href="/wiki/Star_Wars:_Knights_of_the_Old_Republic" title="Star Wars: Knights of the Old Republic">Knights of the Old Republic</a></i> video game, the colors signified the Jedi's specialization.</p>
<p><br /></p>’;