0

I'm putting together a quick extracting function in PHP. Basically, it will read the contents of a given URL and extract the necessary HTML code. It will then put the code into a new page. Now, I've gotten everything working except one thing.

I have a string with the contents of the URL, and now I want to extract text between two tags. Let's say I want to start copying content at a certain tag. That's easy since those tags have classes.

So I'd have the function start with "" It simply searches the document for all text that matches this. I've run into a problem, though. Within the section I wish to copy, there are other tags. As such, if I tell the function to stop extracting at "," the scraper will stop reading at the end of a random tag. Can someone help me write a bit of PHP code that will ensure that the tag the function stops at is the closing tag for the "" and not for some random tag that happens to be in the string?

Thanks in advance.

3

1 Answer 1

3

There is no way to do this and account for every possible content between the tags. Use XmlDocument and parse the HTML.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.