Jump to content

How to find certain parts of text within a file?


VarHyid

Recommended Posts

Hi, Everyone! :)

 

I have an issue and I'm not even sure if it can be done with PHP, but even this info would help me (to stop looking for an answer).

 

I need to populate a (MySQL) database with stuff which is now written in a (HTML formatted) file. Here are my options:

1. Copy/paste each single field via PHPMyAdmin .

2. Write a little script to extract the necessary parts of text from these files to create a CSV-like content which I would then easily INSERT into the db.

 

Example

The files look like this:

 

<!-- SEPARATOR (same throughout the file(s) -->

<tr><td>

<div style="something"><img src="img/what_i_need_to_extract_1.png"></div>

</td><td>

<div style="something else"><b>What I need to extract 2</b></div>
<div style="something else">What I need to extract 3</div>

</td></tr>

<!-- SEPARATOR (same throughout the file(s) -->
etc ...

 

and it goes like... 100 times in each file in the same standard pattern with the "What I need to extract" parts being completely different each time.

 

Since it's possible to tell when each part required for extraction begins and ends, I would expect the script to look for these key-points (according to the example, it would be: img/ to  "></d then "><b> to </b>< and else"> to </div>) and return a result like this (acc. to the example): ('what_i_need_to_extract_1.png', 'What I need to extract 2', 'What I need to extract 3'), (and so on...).

 

Is it possible? Is there a function/option/way to look for a start/end-point like this and fetch the part between these two set points? If so - how? Any help would be appreciated, I'm not expecting a full code, obviously, just a point to the right direction or where to look at would be nice. Thanks in advance. :)

I normally don't suggest long shots but you've had a marathon of zero responses, so:

 

From my memory, PHP cannot get returned system verbose, but I could be wrong:

If your on Linux, try and get PHP to use a system command to return located text from a file.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.