Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/49364-extract-text-from-html-fil/
Share on other sites

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

 

 

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.