Extracting specific Html codes from websites

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
thankyou
Forum Newbie
Posts: 1
Joined: Wed Aug 20, 2008 11:12 pm

Extracting specific Html codes from websites

Post by thankyou »

Hi everyone,

I need help in extracting html codes from websites.
There are some program that can extract captchas from websites. Some directories submitter software has it.

Let me give an example for a better picture.
let's say I want to extract form codes from a page.
So I want this program/script to extract the whole codes from
<form.... until ...</form>

How do I do that in php?
User avatar
it2051229
Forum Contributor
Posts: 312
Joined: Tue Dec 25, 2007 8:34 pm

Re: Extracting specific Html codes from websites

Post by it2051229 »

do you know XML? php has this xml feature... you can parse XML... basically html tags are like xml anyway.. but xml will surely solve your problem.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: Extracting specific Html codes from websites

Post by s.dot »

Look at preg_match() or preg_match_all()

Code: Select all

preg_match_all('/<form>.+?<\/form>/ism', $HTMLContents, $matches);
 
echo '<pre>';
print_r($matches);
echo '</pre>';
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply