Reading HTML Tags

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
User avatar
lenton
Forum Commoner
Posts: 49
Joined: Sun Jun 20, 2010 6:45 am

Reading HTML Tags

Post by lenton »

I'm making a web crawler in PHP and I need some help when getting information from within tags.

For example, if I had this variable:

Code: Select all

$code = "<p>hello <b>How are you?</b> yum <b>I like cake!</b></p>";
How would I get the information within the bold tags into an array like this?:

1. How are you?
2. I like cake!

Thanks for your help!
User avatar
prefer32bits
Forum Newbie
Posts: 10
Joined: Sat Jan 01, 2011 11:55 pm
Location: San Jose, CA

Re: Reading HTML Tags

Post by prefer32bits »

I would use this :

Code: Select all

$array=explode("<b>", $code);
Only problem is, </b> is different from <b>.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Reading HTML Tags

Post by califdon »

Look up regex in Google. such as http://en.wikipedia.org/wiki/Regular_expression.
Post Reply