VarHyid Posted October 9, 2011 Share Posted October 9, 2011 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 https://forums.phpfreaks.com/topic/248738-how-to-find-certain-parts-of-text-within-a-file/ Share on other sites More sharing options...
Freedom-n-Democrazy Posted October 9, 2011 Share Posted October 9, 2011 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. Link to comment https://forums.phpfreaks.com/topic/248738-how-to-find-certain-parts-of-text-within-a-file/#findComment-1277435 Share on other sites More sharing options...
awjudd Posted October 9, 2011 Share Posted October 9, 2011 You could use: http://simplehtmldom.sourceforge.net/ to parse the DOM and then use each of the elements to grab what you want out of it. ~juddster Link to comment https://forums.phpfreaks.com/topic/248738-how-to-find-certain-parts-of-text-within-a-file/#findComment-1277439 Share on other sites More sharing options...
VarHyid Posted October 9, 2011 Author Share Posted October 9, 2011 You could use: http://simplehtmldom.sourceforge.net/ to parse the DOM and then use each of the elements to grab what you want out of it. ~juddster Thank you very much, this might actually do the job Link to comment https://forums.phpfreaks.com/topic/248738-how-to-find-certain-parts-of-text-within-a-file/#findComment-1277455 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.