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. :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.