Convert literature string via Regular Expressions
am 10.11.2003 16:50:58 von Bastiaan Wakkie
--=-0pYwQIU1EBYW409OcWV6
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Hi all,
I'm having difficulties getting the following literature strings ripped
to prepare it to be inserted into the database.
Here 2 example strings:
Hauser, M., Geller-Grimm, F. (1995): Bestimmungsschlüssel für die Weibchen der deutschen Sphegina-Arten (Diptera, Syrphidae). [Key to distinguish the females of the Sphegina species known from Germany (Diptera, Syrphidae).] - Entomology 2(1/2), 3-19. London.
Mazánek, L., Láska, P., Bicik, V. (1999): Two new Palaearctic species of Eupeodes similar to E. bucculatus (Diptera, Syrphidae) [] - Volucella 4, 1-9. Stuttgart.
Pattern is like this:
Author(s) (year): Title in German or English. [If filled than former
title was a German one and this one is the English translation.] -
Source issue, pages. City.
Author:
Year:
Title EN or DE:
Title EN:
Source:
Issue:
Pages:
Press City:
I tried something like this:
preg_match ("/^[..something..]+/", $string, $regs);
echo ("Author: ".$regs[1]."
");
echo ("Year: ".$regs[2]."
");
echo ("Title EN or DE: ".$regs[3]."
");
echo ("Title EN: ".$regs[4]."
");
echo ("Source: ".$regs[5]."
");
echo ("Issue: ".$regs[6]."
");
echo ("Pages: ".$regs[7]."
");
echo ("Press City: ".$regs[8]."
");
But I'm having problems with the spaces and the parentheses that I
somehow can't use in the matching...
Any idea how to split the string in the appropriate parts?
Many thanks,
Bastiaan
--
Bastiaan Wakkie
www.syrphidae.com
--=-0pYwQIU1EBYW409OcWV6
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 7bit
Hi all,
I'm having difficulties getting the following literature strings ripped to prepare it to be inserted into the database.
Here 2 example strings:
Hauser, M., Geller-Grimm, F. (1995): Bestimmungsschlüssel für die Weibchen der deutschen Sphegina-Arten (Diptera, Syrphidae). [Key to distinguish the females of the Sphegina species known from Germany (Diptera, Syrphidae).] - Entomology 2(1/2), 3-19. London.
Mazánek, L., Láska, P., Bicik, V. (1999): Two new Palaearctic species of Eupeodes similar to E. bucculatus (Diptera, Syrphidae) [] - Volucella 4, 1-9. Stuttgart.
Pattern is like this:
Author(s) (year): Title in German or English. [If filled than former title was a German one and this one is the English translation.] - Source issue, pages. City.
Author:
Year:
Title EN or DE:
Title EN:
Source:
Issue:
Pages:
Press City:
I tried something like this:
preg_match ("/^[..something..]+/", $string, $regs);
echo ("Author: ".$regs[1]."<br />");
echo ("Year: ".$regs[2]."<br />");
echo ("Title EN or DE: ".$regs[3]."<br />");
echo ("Title EN: ".$regs[4]."<br />");
echo ("Source: ".$regs[5]."<br />");
echo ("Issue: ".$regs[6]."<br />");
echo ("Pages: ".$regs[7]."<br />");
echo ("Press City: ".$regs[8]."<br />");
But I'm having problems with the spaces and the parentheses that I somehow can't use in the matching...
Any idea how to split the string in the appropriate parts?
Many thanks,
Bastiaan
--
Bastiaan Wakkie <>
www.syrphidae.com
|
--=-0pYwQIU1EBYW409OcWV6--
Re: Convert literature string via Regular Expressions
am 11.11.2003 21:08:14 von Bastiaan Wakkie
--=-cwXYTIUkJeGTL5ZmxROV
Content-Type: multipart/alternative; boundary="=-pDU6lV73QCltmLDT065o"
--=-pDU6lV73QCltmLDT065o
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by hosting.commandprompt.com id hACJlMu04076
Hey,
I Found it out at the end! Thanks anyway.
Here the code to find out for someone that is interested:
$filename=3D"Literature.txt";
$handle =3D fopen ($filename, "r");
while (!feof ($handle)) {
$buffer =3D fgets($handle, 1024);
echo ("
".$buffer."<>");
//.....................Author.................Year.......... .......Titl=
e DE or EN.............EN Title..............................Source.....i=
ssue...........pages......Press
$match=3Dpreg_match ("/^([\wÜÖäüßéñóíá,.-\s]*)\(([\=
d]{4})\)*:\s([\)\(ÜÖäüßéñóíá,.:&?!-\w\s] *)\[([\)\(Ü=
Öäüßéñóí=E1,.:&?!-=E9\w\s]*)\]\s-\s([\s\w]*) \s([\(\/\)\d]=
*),\s([\d-]*).\s([\w]*)/", $buffer, $regs);
if ($match){
echo ("
Matched till now in: $line
------------------------>
>".$regs[0]."");
echo ("
Author: | ".$regs[1]."=
i> |
");
echo ("Year: | ".$regs[2]." |
");
echo ("Title EN or DE: | ".$regs[3]." |
")=
;
echo ("Title EN: | ".$regs[4]." |
");
echo ("Source: | ".$regs[5]." |
");
echo ("Issue: | ".$regs[6]." |
");
echo ("Pages: | ".$regs[7]." |
");
echo ("Press City: | ".$regs[8]." |
e>");
}
else{
echo "String did not match!
";
}
}
fclose ($handle);
?>
Cool he! ;-) I'm starting to like regular expressions. So now I can
happily import 1000 new rows without any problem.=20
bye,
Bastiaan
On Mon, 2003-11-10 at 16:50, Bastiaan Wakkie wrote:
> Hi all,
>=20
> I'm having difficulties getting the following literature strings
> ripped to prepare it to be inserted into the database.
>=20
> Here 2 example strings:
>=20
>=20
>=20
> Hauser, M., Geller-Grimm, F. (1995): Bestimmungsschlüssel für die W=
eibchen der deutschen Sphegina-Arten (Diptera, Syrphidae). [Key to distin=
guish the females of the Sphegina species known from Germany (Diptera, Sy=
rphidae).] - Entomology 2(1/2), 3-19. London.
> Maz=E1nek, L., L=E1ska, P., Bicik, V. (1999): Two new Palaearctic speci=
es of Eupeodes similar to E. bucculatus (Diptera, Syrphidae) [] - Volucel=
la 4, 1-9. Stuttgart.
>=20
> Pattern is like this:
> Author(s) (year): Title in German or English. [If filled than former
> title was a German one and this one is the English translation.] -
> Source issue, pages. City.
>=20
> Author:=20
> Year:=20
> Title EN or DE:=20
> Title EN:=20
> Source:=20
> Issue:=20
> Pages:=20
> Press City:
>=20
> I tried something like this:=20
>=20
> preg_match ("/^[..something..]+/", $string, $regs);
>=20
> echo ("Author: ".$regs[1]."
");
> echo ("Year: ".$regs[2]."
");
> echo ("Title EN or DE: ".$regs[3]."
");
> echo ("Title EN: ".$regs[4]."
");
> echo ("Source: ".$regs[5]."
");
> echo ("Issue: ".$regs[6]."
");
> echo ("Pages: ".$regs[7]."
");
> echo ("Press City: ".$regs[8]."
");
>=20
> But I'm having problems with the spaces and the parentheses that I
> somehow can't use in the matching...
> Any idea how to split the string in the appropriate parts?
>=20
> Many thanks,
> Bastiaan
>=20
> --=20
> Bastiaan Wakkie
> www.syrphidae.com
--=20
Bastiaan Wakkie
www.syrphidae.com
--=-pDU6lV73QCltmLDT065o
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 7bit
Hey,
I Found it out at the end! Thanks anyway.
Here the code to find out for someone that is interested:
<?php
$filename="Literature.txt";
$handle = fopen ($filename, "r");
while (!feof ($handle)) {
$buffer = fgets($handle, 1024);
echo ("<hr><p>".$buffer."<>");
//.....................Author.................Year.......... .......Title DE or EN.............EN Title..............................Source.....issue......... ..pages......Press
$match=preg_match ("/^([\wÜÖäüßéñóíá,.-\s]*)\(([\d]{4})\)*:\s([\)\(ÜÖäüßéñóí á,.:&?!-\w\s]*)\[([\)\(ÜÖäüßéñóíá,.:&?!-é \w\s]*)\]\s-\s([\s\w]*)\s([\(\/\)\d]*),\s([\d-]*).\s([\w]*)/ ", $buffer, $regs);
if ($match){
echo ("<p>Matched till now in: $line <br>------------------------> <i>".$regs[0]."</i>");
echo ("<table border=\"2\"><tr><td>Author:</td><td><i>".$regs[1]." </i></td></tr>");
echo ("<tr><td>Year:</td><td><i>".$regs[2]."</i></td></tr >");
echo ("<tr><td>Title EN or DE:</td><td><i>".$regs[3]."</i></td></tr>");
echo ("<tr><td>Title EN:</td><td><i>".$regs[4]."</i></td></tr>");
echo ("<tr><td>Source:</td><td><i>".$regs[5]."</i></td></tr >");
echo ("<tr><td>Issue:</td><td><i>".$regs[6]."</i></td></tr >");
echo ("<tr><td>Pages:</td><td><i>".$regs[7]."</i></td></tr >");
echo ("<tr><td>Press City:</td><td><i>".$regs[8]."</i></td></tr></table>");
}
else{
echo "<div style=\"color:red\">String did not match!</div></p>";
}
}
fclose ($handle);
?>
Cool he! I'm starting to like regular expressions. So now I can happily import 1000 new rows without any problem.
bye,
Bastiaan
On Mon, 2003-11-10 at 16:50, Bastiaan Wakkie wrote:
Hi all,
I'm having difficulties getting the following literature strings ripped to prepare it to be inserted into the database.
Here 2 example strings:
Hauser, M., Geller-Grimm, F. (1995): Bestimmungsschlüssel für die Weibchen der deutschen Sphegina-Arten (Diptera, Syrphidae). [Key to distinguish the females of the Sphegina species known from Germany (Diptera, Syrphidae).] - Entomology 2(1/2), 3-19. London.
Mazánek, L., Láska, P., Bicik, V. (1999): Two new Palaearctic species of Eupeodes similar to E. bucculatus (Diptera, Syrphidae) [] - Volucella 4, 1-9. Stuttgart.
Pattern is like this:
Author(s) (year): Title in German or English. [If filled than former title was a German one and this one is the English translation.] - Source issue, pages. City.
Author:
Year:
Title EN or DE:
Title EN:
Source:
Issue:
Pages:
Press City:
I tried something like this:
preg_match ("/^[..something..]+/", $string, $regs);
echo ("Author: ".$regs[1]."<br />");
echo ("Year: ".$regs[2]."<br />");
echo ("Title EN or DE: ".$regs[3]."<br />");
echo ("Title EN: ".$regs[4]."<br />");
echo ("Source: ".$regs[5]."<br />");
echo ("Issue: ".$regs[6]."<br />");
echo ("Pages: ".$regs[7]."<br />");
echo ("Press City: ".$regs[8]."<br />");
But I'm having problems with the spaces and the parentheses that I somehow can't use in the matching...
Any idea how to split the string in the appropriate parts?
Many thanks,
Bastiaan
--
Bastiaan Wakkie <>
www.syrphidae.com
|
--
Bastiaan Wakkie <>
www.syrphidae.com
|
--=-pDU6lV73QCltmLDT065o--
--=-cwXYTIUkJeGTL5ZmxROV
Content-ID: <1068580529.32507.1.camel@localhost.localdomain>
Content-Disposition: attachment; filename=smiley-4.png
Content-Type: image/png; name=smiley-4.png
Content-Transfer-Encoding: base64
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAC/UlEQVR42n2T
f2iUdRzHX9/v8zy3u91ulnO5pXGXUUsK1yIY9ke0CDQiodbQKCOnNieaIkKI
/yRhf0QgCeEqViKUYgUOnTE9G5WtjlqBTV1bsnl0tV93u93ux3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