473,411 Members | 2,148 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

Parsing data from a string into an array for each match

I've had experience with PHP building simple websites and have only
scratched the surface of what it's capable of, so in a sense I'm a newbie.
However the problem I have is that I want to be able to read a file, store
it into a string, and be able to look for patterns in it to extract. I know
what the regex expression is for getting the data, but not familiar with how
to read the string and for each match, store it in an array. I haven't been
able to find any sample code and my php geek buddy is on vacation.

<?php

$string = implode(file("classes.txt"));
$string = ereg_replace ("/r|/n", "", $string);

// this is where I have no clue

?>

Regex expression going to be used - "[A-Z]{3,4} [0-9.]{4} [a-zA-Z.
\n\r]*\(([0-9]|Var.)\) [a-zA-Z;,. \n\r-]*"

Also, if you know how to be able to READ a PDF file in PHP let me know.
Cutting and pasting twenty 6.1MB PDFs will get annoying. I'm just trying to
make a script to save me time in the future.

William Holroyd
Jul 17 '05 #1
3 1881
William Holroyd wrote:
I've had experience with PHP building simple websites and have only
scratched the surface of what it's capable of, so in a sense I'm a newbie.
However the problem I have is that I want to be able to read a file, store
it into a string, and be able to look for patterns in it to extract. I know
what the regex expression is for getting the data, but not familiar with how
to read the string and for each match, store it in an array. I haven't been
able to find any sample code and my php geek buddy is on vacation.

<?php

$string = implode(file("classes.txt"));
$string = ereg_replace ("/r|/n", "", $string);

// this is where I have no clue

Regex expression going to be used - "[A-Z]{3,4} [0-9.]{4} [a-zA-Z.
\n\r]*\(([0-9]|Var.)\) [a-zA-Z;,. \n\r-]*"
// I didn't look at the regex, just simply copied it here
$regex = "[A-Z]{3,4} [0-9.]{4} [a-zA-Z.\n\r]*\(([0-9]|Var.)\) [a-zA-Z;,. \n\r-]*";
$num = preg_match_all("/$regex/", $string, $found_array);
if ($num === false) exit('Error in preg_match_all().');
echo '<pre>Found ', $num, ' matches: ';
print_r($Found_array);
echo '</pre>';
?>


Check the fine manual for preg_match_all
http://www.php.net/preg_match_all

--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #2
William Holroyd a écrit le 07/05/2004 :
Also, if you know how to be able to READ a PDF file in PHP let me know.


There's some solution to create but few to actually read PDF.
Maybe you could find enough material in this two famous sites.

An extension to the PDFLib (not free sorry) :
http://www.pdflib.com/products/pdflib/pdi.html

FDPDF project (kind of PDFLib for free) :
http://fpdf.org/?lang=en

Tutorial for FPDF :
http://www.zend.com/zend/tut/tutorial-PDFgen1.php
Jul 17 '05 #3
In article <c7**********@cnn.cns.ksu.edu>,
"William Holroyd" <w.*******@versity-cobalt.com> wrote:
However the problem I have is that I want to be able to read a file, store
it into a string, and be able to look for patterns in it to extract. I know
what the regex expression is for getting the data, but not familiar with how
to read the string and for each match, store it in an array.


<http://nl.php.net/preg_match>
<http://nl.php.net/preg_match_all>

JPK

--
Sorry, <de*****@cauce.org> is een "spam trap".
E-mail adres is <jpk"at"akamail.com>, waarbij "at" = @.
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: supercomputer | last post by:
I am using this function to parse data I have stored in an array. This is what the array looks like: , , , , , , , , , , , , , , , , , , , , , , , ] This is the code to parse the array:
11
by: Martin Robins | last post by:
I am trying to parse a string that is similar in form to an OLEDB connection string using regular expressions; in principle it is working, but certain character combinations in the string being...
4
by: ralphNOSPAM | last post by:
Is there a function or otherwise some way to pull out the target text within an XML tag? For example, in the XML tag below, I want to pull out 'CALIFORNIA'. ...
17
by: Mark | last post by:
I must create a routine that finds tokens in small, arbitrary VB code snippets. For example, it might have to find all occurrences of {Formula} I was thinking that using regular expressions...
3
by: Chris | last post by:
Hi everyone, I'm trying to parse through the contents of some text files with regular expressions, but am new to regular expressions and how to use them in VB.net. I'm pretty sure that the...
9
by: Paulers | last post by:
Hello, I have a log file that contains many multi-line messages. What is the best approach to take for extracting data out of each message and populating object properties to be stored in an...
27
by: SQL Learner | last post by:
Hi all, I have an Access db with two large tables - 3,100,000 (tblA) and 7,000 (tblB) records. I created a select query using Inner Join by partial matching two fields (X from tblA and Y from...
2
by: RG | last post by:
I am having trouble parsing the data I need from a Serial Port Buffer. I am sending info to a microcontroller that is being echoed back that I need to remove before I start the actual important...
6
by: korovev76 | last post by:
Hello everybody, I'm new to python (...I work with cobol...) I have to parse a file (that is a dbIII file) whose stucture look like this: |string|, |string|, |string that may contain commas...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.