torvald_helmer Posted April 30, 2007 Share Posted April 30, 2007 I have a html-file, which I want to extract the some content, and not any tag's. I thoguht I might start like this: $file = file("test.html"); foreach ($file as $line) { some code.... } A example is this line is the file: <tr><td class="felt">Car</td><td>Mercedes<br/></td></tr> How can I get just 'Car' and 'Mercedes' from this line? Has anyone got an idea? I really don't know where to go further... Need help! Quote Link to comment https://forums.phpfreaks.com/topic/49364-extract-text-from-html-fil/ Share on other sites More sharing options...
MadTechie Posted April 30, 2007 Share Posted April 30, 2007 2 options spring to mind strpos & substr or RegEx (ie preg_grep) Edit: fixed preg-grep link Quote Link to comment https://forums.phpfreaks.com/topic/49364-extract-text-from-html-fil/#findComment-241894 Share on other sites More sharing options...
Intelly XAD Posted April 30, 2007 Share Posted April 30, 2007 In this case, I would mess a little with explode explode(splitter, haystack); When you explode, you chop a string in an array. so when you explode on > you can get the usefull things out with the keys... For example: <?php $string = 'Here are more HTML tags ... <td>Example</td> ... Here are more HTML tags'; $string = explode('<td>', $string); // key 1 contains 'Example</td>' (key 0 is empty) $string = $string[1]; $string = explode('</td>', $string); // key 0 contains 'Example' $string = $string[0]; ?> Though you need to be carefull with the keys You can write simple functions for this to make it an easier job, hope this function is usefull Grtz Quote Link to comment https://forums.phpfreaks.com/topic/49364-extract-text-from-html-fil/#findComment-241913 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.