Page 1 of 1

Reading HTML Tags

Posted: Sun Jan 02, 2011 4:34 pm
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!

Re: Reading HTML Tags

Posted: Sun Jan 02, 2011 5:56 pm
by prefer32bits
I would use this :

Code: Select all

$array=explode("<b>", $code);
Only problem is, </b> is different from <b>.

Re: Reading HTML Tags

Posted: Sun Jan 02, 2011 6:40 pm
by califdon
Look up regex in Google. such as http://en.wikipedia.org/wiki/Regular_expression.