From bastiaaw@dds.nl Mon Nov 10 16:00:56 2003 X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id A4A70D1B568 for ; Mon, 10 Nov 2003 16:00:56 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 30987-07 for ; Mon, 10 Nov 2003 12:00:24 -0400 (AST) Received: from sarek.skynet.be (sarek.skynet.be [195.238.3.230]) by svr1.postgresql.org (Postfix) with ESMTP id D3EB5D1B53B for ; Mon, 10 Nov 2003 12:00:23 -0400 (AST) Received: from 126-17.241.81.adsl.skynet.be (126-17.241.81.adsl.skynet.be [81.241.17.126]) by sarek.skynet.be (8.12.9/8.12.9/Skynet-OUT-2.21) with ESMTP id hAAG02fe002077 for ; Mon, 10 Nov 2003 17:00:02 +0100 (envelope-from ) Subject: Convert literature string via Regular Expressions From: Bastiaan Wakkie Reply-To: bwakkie@syrphidae.com To: pgsql-php@postgresql.org Content-Type: multipart/alternative; boundary="=-0pYwQIU1EBYW409OcWV6" Organization: www.syrphidae.com Message-Id: <1068479457.5950.13.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.4-1.1mdk Date: 10 Nov 2003 16:50:58 +0100 X-RAVMilter-Version: 8.4.3(snapshot 20030212) (sarek.skynet.be) X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200311/28 X-Sequence-Number: 2421 --=-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 <bastiaaw@dds.nl>
www.syrphidae.com
--=-0pYwQIU1EBYW409OcWV6-- From bastiaaw@dds.nl Tue Nov 11 20:18:10 2003 X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 9B40AD1B531 for ; Tue, 11 Nov 2003 20:18:10 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 21535-03 for ; Tue, 11 Nov 2003 16:17:39 -0400 (AST) Received: from tsunami.skynet.be (tsunami.skynet.be [195.238.2.85]) by svr1.postgresql.org (Postfix) with ESMTP id 9819FD1B554 for ; Tue, 11 Nov 2003 16:17:36 -0400 (AST) Received: from 126-17.241.81.adsl.skynet.be (126-17.241.81.adsl.skynet.be [81.241.17.126]) by tsunami.skynet.be (8.12.9/8.12.9/Skynet-OUT-2.21) with ESMTP id hABKHJXB000439; Tue, 11 Nov 2003 21:17:19 +0100 (envelope-from ) Subject: Re: Convert literature string via Regular Expressions From: Bastiaan Wakkie Reply-To: bwakkie@syrphidae.com To: Bas syrph Cc: pgsql-php@postgresql.org In-Reply-To: <1068479457.5950.13.camel@localhost.localdomain> References: <1068479457.5950.13.camel@localhost.localdomain> Content-Type: multipart/related; type="multipart/alternative"; boundary="=-cwXYTIUkJeGTL5ZmxROV" Organization: www.syrphidae.com Message-Id: <1068581292.32580.15.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.4-1.1mdk Date: 11 Nov 2003 21:08:14 +0100 X-RAVMilter-Version: 8.4.3(snapshot 20030212) (tsunami.skynet.be) X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200311/36 X-Sequence-Number: 2429 --=-cwXYTIUkJeGTL5ZmxROV Content-Type: multipart/alternative; boundary="=-pDU6lV73QCltmLDT065o" --=-pDU6lV73QCltmLDT065o Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Hey, I Found it out at the end! Thanks anyway. Here the code to find out for someone that is interested:

".$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 ("

Matched till now in: $line
------------------------> ".$regs[0].""); echo (""); echo (""); echo (""); echo (""); echo (""); echo (""); echo (""); echo ("
Author:".$regs[1]."
Year:".$regs[2]."
Title EN or DE:".$regs[3]."
Title EN:".$regs[4]."
Source:".$regs[5]."
Issue:".$regs[6]."
Pages:".$regs[7]."
Press City:".$regs[8]."
"); } 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. 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]."
"); > 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 -- 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 <bastiaaw@dds.nl>
www.syrphidae.com
--
Bastiaan Wakkie <bastiaaw@dds.nl>
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 /yRhf0QgCeEqViKUYgUOnTE9G5WtjlqBTV1bsnl0tV93u93ux3PP93meb/8s KBNf8P7jw/v9+fz1/sD/iQI7gB7AWdApoGPB+w/ihvnI/bHKbfu2NLF2zUrM cAw8G2d+mIGBi+w/nGE46XQBnTc7cOFAZ+MTO1/bgDBCuIVxnPwIQhgYwXqM QA2qMMahd+O8fWLmAvAkgLGw/MGbOx55fueuF/FKKVRxHF/NIaQFgO+kcQtj gGZ1cwyjOLXiuyG7DuiVQLSx4fat2zvX4dmTeOVphDCwvUqkWcVk2mfDnkGE tPCdLEJabH95CfctN7YBUQk83XNoMUJaTE+McuT476x9pZfmZ3sI1D7D8fMe P/2a4a3uGaqWt6Ly1zBDdbzadhvAowLomrn0eocqXMeoqCVU+xgaE2mYlKb6 sSINtG58gzOnTzGf/BR7+hukWUni52u07p04aS5bdudmAN/NURZ3oSe+RBhh hLTQGsqZBKd7Pic3fhSVGwLAtaeoX2IAPGem02kQJrP5EHJRHYb0CHhZtG+C dtFeiezIO2h3Hu17OI6DqxzyRR8AadvlXu0WqDSm6O87xkzWx6p+AF/l8N08 vmejvRLaV7jKJjNnEwwvJTXtASQk0FecOEsoUs/69RuJx8+RGOgjuLgZK7IS zBo8X9L/w1+07RnmnqZ2RpNlrg7lAU4IILrq3sh437GnMCruIFD9IL8MfsvQ pUE+OiO4fGWYRVUGhw+2sablIZJXPiN+cYwPT2b4LaUb/mli94Etsfatm5pw i0kisU1Y4RUIIfHsSTQalR/lcuJj/ph0Od8/y9G46gI6/13lrzrW1bTs3Rwm EKxGyAp8lWN2rkShpCkrzfU/FYkf53j/rPM18PjNnqn77jrZ/kJLFasaQ4SD glJZk533GUspvjiXZSTFJ8BL3IIosBv4HlBAGrgKvAc8fGP4b4kpTGRKdd96 AAAAAElFTkSuQmCC --=-cwXYTIUkJeGTL5ZmxROV--