I got some problems with my patterns. Hope somebody could help me with this.
given a string
$string = Mutualism has been retrospectively characterised as ideologically situated between individualist and collectivist forms of anarchism.<ref>Avrich, Paul. ''Anarchist Voices: An Oral History of Anarchism in America'', Princeton University Press 1996 ISBN 0-691-04494-5, p.6<br />''Blackwell Encyclopaedia of Political Thought'', Blackwell Publishing 1991 ISBN 0-631-17944-5, p. 11.</ref> Proudhon first characterised his goal as a "third form of society, the synthesis of communism and property."<ref>Pierre-Joseph Proudhon. ''What Is Property?'' Princeton, MA: Benjamin R. Tucker, 1876. p. 281.</ref> Another is <ref name=rupert/>
I want to remove strings inside the <ref> (<ref name='something'></ref> or <ref></ref>) or remove the single ref tag <ref name='sss' />
after replacing the final out put should be :
Mutualism has been retrospectively
characterised as ideologically
situated between individualist and
collectivist forms of anarchism.
Proudhon first characterised his goal
as a “third form of society, the
synthesis of communism and property.”
Another is
my code doesn’t seem to work
$pattern1[] = "/<ref[^\/]*\/>/is"; //remove <ref name=something/>
$pattern1[] = "/<ref[^\/]*>(.*?)<\/ref>/s"; //remove ref <ref>some text here</ref>
preg_replace($pattern1,"\n", $string);
instead it outputs :
Mutualism has been retrospectively
characterised as ideologically
situated between individualist and
collectivist forms of anarchism.
”Blackwell Encyclopaedia of Political
Thought”, Blackwell Publishing 1991
ISBN 0-631-17944-5, p. 11.</ref>
Proudhon first characterised his goal
as a "third form of society, the
synthesis of communism and
property." Another is
I guess it got caught up with the <br />
The Problem is that your first pattern is also matching
[^\/]*matches the followingthe solution is to use
/<ref(?:[^\/&]|&(?!gt;))*\/>/isto match tagsin this case we use
(?:[^\/&]|&(?!gt;))*instead of[^\/]*The first
(?:[^\/&]|&(?!gt;))*Matches any character excluding / and &, As the first option, or & if its not followed by gt; i.e. not part of a > symbol as the second option here the(?!gt;)is a negative look ahead assertion (see http://www.php.net/manual/en/regexp.reference.assertions.php) this simply means with out consuming the gt;, insure the next 3 character don’t match this pattern.The Second simply matches any character that’s not a /.
so the following code
outputs