Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Complicated Email Parse Or Text Extraction And Database Insertion


I am trying to strip some data out of numerous emails and place it in
my database. I know that this seems as if it has been done before.
But, this is a little different. First, the numerous emails all have a
set of data that needs to be extracted and inserted into the database.
Some of the data in the email is id, name, address, city, state, zip,
company, etc. The catch is that the date is formated and presented
differently in each email. Take into consideration the following email
examples:

- excert from email #1
ID:.............. 12345
Name:............ JOHN DOE
Address:......... PO BOX 9999
City:............ Somecity
State:........... CA
Zip Code:........ 90210 ....




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
String Insertion And Extraction
is there a function to replace  a section af a string with another regardless of the values and to do the reverse i.e.

$srt1 = "ABCDEFGHIJKLM")
$str2 = "XY

// insert $str2 in to $str1 [3] and [4]
$srt1 = "ABCXYFGHIJKLM")
AND
$str = $str1 positions [7] and [8]
$str = "HI";

I want to do some incripion on text. OR will I have to create something?

Preparing Text For Insertion Into Database
I insert text into a MySQL Database using a TEXT field. PHP syntax is:

$query = "INSERT INTO data (text_field) VALUES('$text_field')";

The problem is, when the user has an apostroph (like "friggin' cool") in the text, MySQL misinterprets it, and the query is invalid. Is there a PHP function that formats the that input so it can be entered into the database?

Getting Primary Key Value Of Last Database Insertion
I have a very simple issue.  I have a bunch of data I'm inserting into a database to create an article.  When complete, I want to redirect to the article, but I need the node_id.  It just so happens that the node_id is the Primary key and is automatically generated by mySQL at insertion time.  Is there an easy way to get the value of the Primary key for the most recent insertion?

Form Calculation Before Database Insertion
My problem is that i want to make a form where will be made calculations and after the calculation are made, the user should press submit and then, all the values from the form should be inseted into a database.

My code is writen under these lines, but all I want to do is the value code to be calculated from Nume and Prenume (for example, if the Nume value is 2 and Prenume value is 3, in the form the value of code should be 5. Code=Nume+Prenume, but i don't know how to write to make the calculation in real time. Code:

Today's Date In Database Insertion
How do I insert today's date in a certain database row without using the date() function for a string?  For example, when you use PHPMyAdmin to insert a new table row and there's a column with the type "date", it gives you options such as CURDATE, NOW, etc.  How would I use that in a database query?

How Do I Use "foreach" Construct With Database Extraction
Below are excerpts from two PHP scripts that I am working on. What I am wanting to do is determine if the $UserName variable exists in the database tables "California" and "NewYork". If the $UserName variable is present on the first iteration the script will output "UserName is in this table!" and so forth for each iteration. PHP Code:

Parse Email
Is it possible to direct an email message to a PHP file that will parse the information and store it in a MySQL database? If so, can anyone direct to me to a tutorial or a book so that I can figure it out? I know how to open csv files and put them in a database, but not an email.

Parse Email
I'm trying to extract information from a raw e-mail. I'm using a parseMail() class to parse out all of the header information and content information. I am having trouble figuring out the best way to get the e-mail body. JUST the text of the e-mail. Any suggestions?

Parse A String With An Email Address
I need to parse a string with an embedded email address.
The string always has the format NAME (name@domain) SOMETEXT.
What I need to get is the email address as name@domain.

I came up with this (I know it's broken, but it's a first start):

<?php

function ParseTicketEmail($ticket)
{
global $TicketEmail;
for ($i=0; $i< strlen($ticket); $i++){
//we need to pass everything between ( and ) to $TicketEmail nothing else
do {
$ticket[$i] = $discarded;
} while ($ticket[$i] != '(');
while ($ticket[$i] != ')'){
$TicketEmail = $TicketEmail . $ticket[$i];
}
}
return $TicketEmail;
}

$ticket = "hello (world@world.com) bla";
print "$TicketEmail";
print "$discarded";
?>

But that doesn't return anything for either $TicketEmail or $discarded.
So:

a: why doesn't it return anything for either string? (It's too early in the morning here)

b: does anyone have such a function anywhere for me to check out for how to do it?

Parse An Email File For Four Variables (easy-intermediate)
Just Beginning to get my feet wet with php, and i have been presented with a challenge (on a deadline even)

We are sent a series of email bullitins daily, and they need to be parsed, and sent to a mySQL database (the database is already prepared to take the incoming messages)

Heres what i've got:
The Message will always begin with:
Return-Path: <push_services@prnewswire.com>
(or some other address)
i would liek to send this to tblMail.MailAddy

next come the junk:
Received: from mail01-ewr.pilot.net (mail-ewr-1.pilot.net [206.98.230.18])
by mail.cintek.com (8.9.3/8.9.3) with ESMTP id HAA29427
for <webguy@cintek.com>; Thu, 13 Jul 2000 07:32:05 -0600
From: push_services@prnewswire.com
Received: from prnmail4 (prnmail4.prnewswire.com [199.230.26.98] (may be forged)) by mail01-ewr.pilot.net with ESMTP id JAA24918 for <webguy@cintek.com>; Thu, 13 Jul 2000 09:22:38 -0400 (EDT)
Received: from hssmtp3 ([198.199.176.20] helo=hssmtp3.prnewswire.com)
by prnmail4 with esmtp (Exim 3.02 #1)
id 13Cj2D-0001Iz-00
for webguy@cintek.com; Thu, 13 Jul 2000 09:28:13 -0400
Received: from [199.230.20.132] (helo=hspdl001.prnewswire.com)
by hssmtp3.prnewswire.com with smtp (Exim 2.05 #1)
id 13Civu-0003sM-00
for webguy@cintek.com; Thu, 13 Jul 2000 09:21:42 -0400
Received: by hspdl001.prnewswire.com (SMI-8.6/SMI-SVR4)
id JAA15992; Thu, 13 Jul 2000 09:21:25 -0400
Date: Thu, 13 Jul 2000 09:21:25 -0400
Message-Id: <200007131321.JAA15992@hspdl001.prnewswire.com>
To: webguy@cintek.com

(it will Always end with To: webguy@cintek.com)

then the message Subject, and Body:
Subject: Researchers Unveil Data on VIRAMUNE(R) (nevirapine) for Prevention of Mother-to-Child Transmission of HIV in Developing Countries
Status:

Researchers Unveil Data on VIRAMUNE(R) (nevirapine) for Prevention of
Mother-to-Child Transmission of HIV in Developing Countries

- More than 1,300 South African Women Participate in Landmark SAINT Trial -

DURBAN, South Africa,
Story Story Story etc.

(What i would like to do is parse the Topic in to its own column, and the message body in to an other.)

(The End of the message Always ends with the word SOURCE, and then a lot more of unneeded information. i would like to drop all of that.)

Can this be done with PHP? Does Anyone have any suggestions on how i would execute it? Feedback would be bliss.

Parse Text From HTML Website, Dump Into DB
I am working on a script to extract statistics (which is updated daily) from
a website, and insert them into a MySQL database. I want to take this
website:
http://www.usatoday.com/sports/bask...players0304.htm
and strip off all the HTML tags and etc, make it look like
http://www.enlhoops.com/ratings/parsed.txt
and then insert each players stat line into the database.

I have begun writing the script, getting the file, striping html tags off,
but that doesn't seem to work too well.

Parse Caller ID To MySQL Database?
I'm wondering if anyone can help me with an approach for getting caller id data into a mysql database. I'm thinking if I could somhow convert the CID data to XML I could FTP the XML data to my server on a schedule and run a script on my server to get the XML data into my db. But how can I extract CID data? Does anyone know of any tools..opensource or otherwise?

Open A File And Parse It To A Database.
I would like to have a php script open a text file, that is tab delimited, and put it into an array, then have the contents of the array put into fields of a mysql database. Here is what I have so far. It uses && as the delimiter, but seems to have some problems. I would rather use a tab as the delimiter, and still need to be able to have it loaded into a database. Code:

Complicated SQL Question
Pardon my lack of SQL knowledge. If I have two tables like this:

weblogs{
id
title
mainContent
}

entries{
id
title
mainContent
belongsToWhichWeblog
}

The last field in entries holds the id of the weblog to which the entry
belongs.

Suppose I want to select the id and title of the weblogs, but I want my
ORDER BY clause to somehow say that the weblogs should be ordered by
how many entries belong to that weblog. If there are two weblogs with
ids 4 and 54 and 4 shows up in belongsToWhichWeblog 23 times and 54
only shows up 12 times, then I want the weblog with the id of 4 to come
first in the ordering.

Is there a way to do that? Mind you, I've a somewhat new version of
MySql in the 3.x series installed, but for various reasons I can not
upgrade to version 4.

Complicated While Loop For A Simpleton
First, I apologize if my posting format is improper. The code below does
what I intended it to do, but presently only displays 1 table entry. I've
grown it to this point, but really need it to loop through the table and do
everything where data_store_no matches $store_no. I've tried placing where
at a couple different points with no real success - it either doesn't work
at all, exceeds the time allowed for a process (presently set to 60 sec) or
still only displays one table row. I regularly have problems understanding
the online documentation and am obviously way over my head. Am I trying to
do too much for it to loop? I need to display, in table format, 4 fields
from each row that appears in the table where it matches store_no. I am
limited to php ver 4.3.2. Any efficiency pointers and stupid mistake
notices are also welcome.

Code: ( text )

Complicated Join Query.
I know what im trying to do is possbile just not sure how! This is what i have already but its just to start

$query = "SELECT m2.ModelID FROM models m1 INNER JOIN deals m2 ON m1.modid=m2.ModelID
WHERE m1.modid='$modid'";

Basically i have a table called 'deals' with my mobile phone deals and my mobile phones are stored in 'models'. On this particular page the ModelID from the models table is in the URL as a variable. What id like to do is if the deals table has no deals in it based on the ModelID then dont show any deals if it does then show.

Sorting Complicated Array Challenge
What is the best way to organize an array that contains common information? PHP Code:

Complicated Pagination Logic Problem
'll try to explain this as clearly as possible, sorry if it's unclear.

You have in your directory /foo 42 images

You have in your database metadata for 30 out of those 42 images

You have to display all 42 images in the /foo directory whether they
have database metadata or not.

If any of the 42 images have metadata, you must display the metadata,
else, you don't.

With me so far? Good, it gets wild from here.

You have a requirement for pagination.

Your pagination limit is to only show 20 images at a time.

The only way I know how to do this is to get all of the images out of
the filesystem pertaining to /foo, all of the metadata out of the
database pertaining to /foo, and logically combine them (using
array_merge()) into a single resultset and display, metadata or not.

However, to paginate to the next page, you'll have to have had stuffed
THE ENTIRE RESULTSET into a $_SESSION variable and splice that.

That of course is not good. But what on earth else do I do? If I am not
to use $_SESSION, how would I paginate such an exotic resultset?

XML Value Extraction
Hey there,

I have loads of XML files with formats such as:

Url Extraction
can someone please tell me how I can get everything I need from a URL AFTER the third / including the third /. For example :

(I host my own website atm to work offline

http://xxx.xxx.xxx.xxx/home/comments.php?Item=xxx

from the url with whatever the code is i would want:

/home/comments.php?Item=xxx

Database Search -text Database...
Can anybody tell me how to search a flat file database delimited by |. I have exploded the data and managed to get it into a table but want to restrict the final table contents by a search.

The table code at the moment is below - I'd be using a htm file to submit the data. and hopefully be able to search by partial searches eg big would return big and bigfoot. Code:

Avi Image Extraction
Does anyone know if it's possible to extract out the first image of an avi upon that avi being uploaded using file upload? What I'm trying to do is to automatically get a static image of the avi as the avi is being uploaded (so it can be used as a sample so the user can determine if they want to download the avi).

I am somewhat familiar with the GD and ImageMagick, but I don't think this can be done with either of those.

Strings Extraction!?
im using sockets and php-win.exe to make a fully functional WEB SERVER!!! "PHP SUPPORTED" I have created everything so far, and I need help with the fnctinonality.  so far I can acess the main page on both the local (1924) and remote (80) ports, but I need to be able to get the request: Code:

Email Script/Javascript Parse Error: Syntax Error, Unexpected T_STRING
I've made a email script to include javascript. Now what I want to do, is that I want to hide the link in status bar when I hover over it. I've implemented javascript into the code but I keep getting the following error:

Parse error: syntax error, unexpected T_STRING in /home/****/public_html/fbmail/contact.php on line 12

Here is line 12:
$message .= '<a href="http://www.mysite.com/" onMouseOver="window.status='Click here to continue.'; return true;" onMouseOut="window.status=''; ">Click here to continue ..</a>'; The complete code:

Preg+data Extraction?
Basically what I am doing is creating some bb code for my blog script right now but I have run into a little problem with preg. I don't know how to extract data for manipulation.
What I would like to do is have my script loop through the string until it finds a url wrapped around like below...

Code:
["[BASE URL HERE]"]
Extract the url into a variable and continue to loop through the code looking for

Code: [[PATH]]
then extract the path found between the double square brackets into another variable, then use a temp var. to append the contents of the ["[]"] and [[]] together to be placed in a hyper link...

then continue on looping through until either another ["[base url]"] is found or the end of the string has been reached.

Now with my limited understanding of regular expressions in php I believe the regex for the two codes above would be something like this:

Code:
bb style code: ["[BASE URL HERE]"]
regex: /["[(*.?)]"]/is

bb style code: [[path]]
regex: /[[(*.?)]]/is

How would I accomplish the above?

MySQL Data Extraction
Using the following code (with MySQL user and password removed , the data extracts correctly, but the carriage return () doesnt seem to be working, the data is just displayed across the screen. Code:

Plain Text Email
I'm wanting to protect all inputs for sending a plain text email, in a common
routine.

Have just found POSIX [:print:] which I thought looked useful.
I didn't want to use htmlentities(); because it's a plain text email.

Would this protect me from anyone sending spam though this?

$raw = stripslashes($raw);
$raw = preg_replace("/(content-type|bcc:|cc:|onload|onclick)/i", "DELETED",
$raw);
$raw = strip_tags($raw);
$raw = preg_replace("/[^[:print:]]/", " ", $raw);
$raw = substr($raw, 0, 500);
$raw = trim($raw);

Or, should I use:
$raw = htmlentities($raw, ENT_NOQUOTES);

The email address would obviously be different.
This would cover just the name, subject and message.
I don't need newlines etc.

Email Box - Text Editor
I'm writing a PHP program that will mass email to my clients in my database. Does anyone have any ideas how to create a email box similar to yahoo o Googles compose email form? It would be nice to edit text size and color.

Random Extraction Of Rows From Mysql Db
I want to pull out data from a mysql database in a random order. I want multiple rows pulled out and I want next and prev buttons. I have it all working (the next and prev part) but when I add the ORDER BY RAND ( ) part I get the error "Warning: Supplied argument is not a valid MySQL result resource" Can anyone help me? Can you get random results this way if you also want to use limit to put a certain number of results to a page? Here is my code:

Simple Question On String Extraction
I'm having to modify a PHP script even though I have little knowledge of PHP
itself. The script extracts specific strings from an html file, and I need
to it extract some further information.

Specifically, each file represents an article written by an author. The
author's name is typically preceded by a 'By' or a 'by', then it goes on
till there's a carriage return.

So for example, the file might contain something like this:

The Need For Regeneration

by <b>John Smith</b>

We have seen the waste that has been produced....

(rest of article)

or

How To Make Lots and Lots of Money Writing PHP

by The Supreme Coder

The first thing you need to know about making money is...

(rest of article)

So I need code that will start searching the file from the beginning for the
words 'by ' or 'By ', then grab everything that follows that until it gets
to a new line and assign that to a variable. In the examples I have given
above, it would grab '<b>John Smith</b>' and 'The Supreme Coder'. I've seen
a function called preg_match which might do the job, but it uses regular
expressions which I have little knowledge of.

Would any person be so kind as to post what arguments I would need to call
this function with?

How To Read HTML Email Text?
I've done a couple of hours web-searching without turning up many
answers so far, and I guess I could figure it out (eventually) from
the MIME format, but here goes with my question...

I don't have any problems reading text emails, but can anybody direct
me to some PHP source code that will read (the text inside) an HTML
email, specifically the "From", "Subject" and especially the message
body?

I would like the code to be able to differentiate between (i.e. know
that it is) a text or an HTML email, and I would like the code to
ignore any attachments.

I don't expect the incoming email to have any (or large) attachments,
but I hope that any code samples can handle the possible case of big
attachments coming along for the ride.

Incidentally, if I did (not this time) want to handle large
attachments, can PHP and/or servers handle megabytes of data being
read into a string variable through fread()? I'm just getting into
this stuff, and not sure of what areas would be a resource and/or
performance hog.

All Text Email - How Do You Add Line-breaks?
Sending an all text email through php.

How do I put line breaks in the message, I was unable to google it

I know you can use "", but like, what else can I do, what is this stuff even called, language, so I can find out what the stuff does?

Conditional Email Text To Hyperlink
I am trying to write a content management section for a web site.

I have managed so far to use htmlarea to give users a basic, but user
friendly interface by which to edit the page content.

The user can add emails by symply typing john@example.com - IE automatically
converts this to a hyperlink. The trouble is sometimes the users use plain
text. I have been using the following line to convert plain text to a
hyperlink:

$pagetext=ereg_replace('[A-Za-z0-9_]([-._]?[A-Za-z0-9])*@[A-Za-z0-9]([-.]?[A-Za-z0-9])*.[A-Za-z]+',
'<a href="mailto:?subject=Email%20from%20web%20site"></a> ',
$pagetext);

This works well - BUT it completely screws up any existing hyperlinks. Is
there a way to convert the plain text email address in to a hyperlink only
if it is NOT part of a hyperlink.

Basically I need some way of checking
* If it's plain text > convert to a hyperlink
* If it's already an email hyperlink leave it alone.

I have tried looking up and testing everything I can think of - but am
finally asking around before I go mad.

Displaying Text/html In Web POP Email
is it possible that message from web POP mail ( through sockets) appears as html (or text) if it is sent as html, not to appear like source file of the html document? I use web POP mail which is not mine and it displays without problem emails sent as text/plain but shows complete source with all tags if the email is sent as text/html, in other words, it´s useless and very hard to read for user.

Get All The Email Addresses From A Text File
I have a .txt file with a lot of text mixed with some email addresses. I
would like to get all the email addresses in a $mails[] variable. Does
anyone know how to do this in php.

Sending Text And Html In One Email
i've put close to 10 hours into this today and i'm not getting results. i simply want to create and send emails that can be viewed by both text based and html based email clients. i've scoured the PHP manual and related comments and nothing is working. I also don't want to use a big bloated open source library as my needs are simple...text...html...that's it. 

can someone point me to code that's working for them (across all popular email clients) or to a tutorial that actually works?

Extracting Email Attachment (Text)
What's the best way to extract email attachments that's encoded in base64?  I can run the base64 encoded stuff through base64_decod(), but I want to know if there is a function to handle attachments.

Example:
------_=_NextPart_001_01C7C330.9D7B678C
Content-Type: text/plain;
 name=report.csv
Content-Transfer-Encoding: base64
Content-Description: report_=.csv
Content-Disposition: inline;
 filename=report.csv

Webbased Email Client With Japanese Text
I am developing the mail client using PHP, when I try to send a mail using mail() of PHP. All the text written in Japanese language converted to junk characters. How can I send the mail with japanese language using PHP only.

Sending Both HTML And Plain Text Email.
I am using php to send weekly newsletters to my mysql database, the emails are always in HTML only.

I was wondering if anyone knew how to send both types so that if they can't view HTML emails it will show just text?

Plain Text Email Spacing Issues?
PHP Code:

// create final message, $text refers to the textarea they typed the original message in $message2 = "Dear $firstname,

$text

Regards,
The Team......

Multi-part Email With Text And Attachment
I'm having some problems adding additional function to one of my scripts. I was successful in creating a tool to send out emails with HTML file attachments to our new customers. This works great.

However, now I want to add in plain text to the body of the email as well. This is causing me a problem. I'm sure it's a problem with the header since I can create the text and the attachment works fine from my previous script. Here's what I have to create the headers: PHP Code:

How To Extract An Email-address From A Text File
Can somebody show me a quick code snippet to reliably extract an
email-address form a text file ?

Validate An Email Form Text Filed
How would i run a check in my datacheck page to see if the user entered an email address in a form text field?

if(empty($email_address) || - NOT VALID EMAIL STUFF HERE -){
   $msg[] = $error12;
}

Trouble Extracting Email Address From Text File
I'm trying to put together a script that will read an email box set up for newsletter bounces and remove the bad addresses.

There's an old script I've worked with that looks for --- Permanant fatal errro ---, but not all the bounced emails have that line included (3 out of about 700 do).

I need to find the bad address, then delete that address out of the database. I've got the deleting out of database down, but am not sure how to find any email address & delete it.

How To Delete Single Email Adres From Text File
I have a textfile:

bla@domain.com
blabla@domain2.com
haha@domain.com
la@domain3.com
zaza@domain4.com

How can I delete a single email from that text file ? E.g. I want to delete blabla@domain2.com so that the textfile will be:

bla@domain.com
haha@domain.com
la@domain3.com
zaza@domain4.com

How can this be done ??

How To Send A Plain Text Version Of An Email With Html
how can u send a plain text version of an email with the html so that
the users mail client can access this plain text version?

User Inputted Text Wont Show In Email
I copied the contact_us page,renamed it, and added some fields which I want added to an email. The input fields show on the site but the user inputted text doesn't get added to the email, just the comment text gets added. Its basically going to be an application for employment when done but I'm just trying to get it to work with the four added questions. Code:

Form To Email AND Database
The server I am on requires using cgiemail to send form data. I want to also send this data to a mysql database using php. Is this possible? How?

Database/Email Script
I am no PHP programmer. At my current job I made it known that I was no
PHP programmer during the interview. Still they have given me a script
to write with the understanding that it will take me a while (This
information is just for general knowledge as I don't want anyone
thinking I am trying to be dishonest with my intentions. Also, I do not
portray myself as something I am not. I am a beginner.)

Anyway, what the script needs to do is to take variables passed from an
HTML form and do two things. One is read it into a database. The other
is to send me an email with all of the customer's information.

//Name of the script is test.php
<?php
//I am using this echo command to make sure that the variables where
passed correctly.
echo $_Post['FName']; //Never displays
//Here is where the script for the database connections starts
$username='username'
$password='password'
$hostname='localhost'
$databasename='database'
//Here is where the database connection is actually made
$conection = mysql_connect($hostname, $username, $password);
mysql_select_db($databasename) or die ("Cannot connect to
database");
//With the database connection open, I start to insert the data from
the HTML form.
$result = mysql_query("INSERT INTO table() VALUES($FName,
$LName, $Company, $Title, $Address, $Apt, $City, $State, $Zip, $Phone,
$Fax, $Email, $Var1, $Var2, $Var3, $Var4, $Var5)");
//After reading the information into the table, we close the database
connection
mysql_close();
//This is where the email script starts (Both the database and email
scripts are inside the same php tags)
$mail_to="email address";
$mail_subject = "Review Registration";
$mail_body = "First Name: $_Post[FName]";
$mail_body .= "Last Name: $_Post[LName]" ;
$mail_body .= "Company: $_Post[Company]" ;
$mail_body .= "Title: $_Post[Title]" ;
$mail_body .= "Street: $_Post[Address]" ;
$mail_body .= "Apt: $_Post[Apt]" ;
$mail_body .= "City: $_Post[City]" ;
$mail_body .= "Zip: $_Post[Zip]" ;
$mail_body .= "Phone: $_Post[Phone]" ;
$mail_body .= "Fax: $_Post[Fax]" ;
$mail_body .= "Email: $_Post[Email]" ;
$mail_body .= "Var1: $_Post[Var1]" ;
$mail_body .= "Var2: $_Post[Var2]" ;
$mail_body .= "Var3: $_Post[Var3]" ;
$mail_body .= "Var4: $_Post[Var4]" ;
$mail_body .= "Var5: $_Post[Var5]" ;..........


Copyright © 2005-08 www.BigResource.com, All rights reserved