-
Notifications
You must be signed in to change notification settings - Fork 0
/
regex_replace.php
19 lines (16 loc) · 4.44 KB
/
regex_replace.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
require_once 'common.php';
$text = <<<AAA
<div style="float: left; margin: 0.5em 0.9em 0.4em 0em;"><a href="/wiki/File:Ulysses_Grant_1870-1880.jpg" class="image" title="Grant in 1876"><img alt="Grant in 1876" src="//upload.wikimedia.org/wikipedia/commons/thumb/d/d7/Ulysses_Grant_1870-1880.jpg/100px-Ulysses_Grant_1870-1880.jpg" width="100" height="133" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/d/d7/Ulysses_Grant_1870-1880.jpg/150px-Ulysses_Grant_1870-1880.jpg 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/d/d7/Ulysses_Grant_1870-1880.jpg/200px-Ulysses_Grant_1870-1880.jpg 2x" data-file-width="1200" data-file-height="1600" /></a></div>
<p><b><a href="/wiki/Ulysses_S._Grant" title="Ulysses S. Grant">Ulysses S. Grant</a></b> (1822–1885) was the <a href="/wiki/List_of_Presidents_of_the_United_States" title="List of Presidents of the United States">18th</a> <a href="/wiki/President_of_the_United_States" title="President of the United States">President of the United States</a> (1869–77). He graduated from the <a href="/wiki/United_States_Military_Academy" title="United States Military Academy">U.S. Military Academy</a> at <a href="/wiki/West_Point,_New_York" title="West Point, New York">West Point</a> and retired after serving in the <a href="/wiki/Mexican%E2%80%93American_War" title="Mexican–American War">Mexican–American War</a>. When the Civil War began in 1861, he rejoined the U.S. Army and won major victories at <a href="/wiki/Battle_of_Shiloh" title="Battle of Shiloh">Shiloh</a> and <a href="/wiki/Siege_of_Vicksburg" title="Siege of Vicksburg">Vicksburg</a>, and in the <a href="/wiki/Chattanooga_Campaign" title="Chattanooga Campaign">Chattanooga Campaign</a>. After promotion to <a href="/wiki/Commanding_General_of_the_United_States_Army" title="Commanding General of the United States Army">Commanding General</a>, Grant confronted <a href="/wiki/Robert_E._Lee" title="Robert E. Lee">Robert E. Lee</a> in a series of bloody <a href="/wiki/Overland_Campaign" title="Overland Campaign">battles in Virginia</a> in 1864, trapping Lee's army in the <a href="/wiki/Siege_of_Petersburg" title="Siege of Petersburg">siege of Petersburg</a>. Lee's surrender to Grant at <a href="/wiki/Battle_of_Appomattox_Court_House" title="Battle of Appomattox Court House">Appomattox</a> on April 9, 1865, ended the war. After the war, he implemented Congressional <a href="/wiki/Reconstruction_Era" title="Reconstruction Era">Reconstruction</a>. Elected president <a href="/wiki/United_States_presidential_election,_1868" title="United States presidential election, 1868">in 1868</a>, Grant led the <a href="/wiki/Republican_Party_(United_States)" title="Republican Party (United States)">Republicans</a> in their effort to remove the vestiges of Confederate nationalism, protect <a href="/wiki/African_American" title="African American">African American</a> citizenship, and support economic prosperity nationwide. In foreign policy, Grant sought to increase American trade and influence, while remaining at peace with the world. His presidency has often come under criticism for tolerating corruption and, in his second term, leading the nation into an economic depression. After an unsuccessful attempt at nomination for a third term in 1880, he completed his <a href="/wiki/Personal_Memoirs_of_Ulysses_S._Grant" title="Personal Memoirs of Ulysses S. Grant">memoirs</a>, garnering critical acclaim and financial success. (<a href="/wiki/Ulysses_S._Grant" title="Ulysses S. Grant"><b>Full article...</b></a>)</p>
<p>Recently featured: <a href="/wiki/Fanny_Bullock_Workman" title="Fanny Bullock Workman">Fanny Bullock Workman</a> – <i><a href="/wiki/I_Never_Liked_You" title="I Never Liked You">I Never Liked You</a></i> – <i><a href="/wiki/Sonic_X" title="Sonic X">Sonic X</a></i></p>
<div style="text-align: right;" class="noprint"><b><a href="/wiki/Wikipedia:Today%27s_featured_article/April_2015" title="Wikipedia:Today's featured article/April 2015">Archive</a></b> – <b><a href="https://lists.wikimedia.org/mailman/listinfo/daily-article-l" class="extiw" title="mail:daily-article-l">By email</a></b> – <b><a href="/wiki/Wikipedia:Featured_articles" title="Wikipedia:Featured articles">More featured articles...</a></b></div>
AAA;
$regex = '#<a|img[\s\S]*>#mU';
$replace = '';
$clean = preg_replace($regex , $replace , $text);
p($clean);
$regex = '#<([\s\S]+)>#mU';
$replace = '[${1}]';
$reformated = preg_replace($regex , $replace , $text);
p($reformated);