-4

is there a function in PHP that could parse the html data below to show the following.

John Lastname
my address
24
1998-03-20 8:15:31 pm
anything
1.1.1.1

This is the html

<b>Name:</b> John Lastname<br />
<b>Address:</b> [my address] <br />
<b>Age:</b> [24] <br/><br />
<b>Date of Birth:</b> [1998-03-20 8:15:31 pm] <br />
<b>Hobby:</b> [anything]<br /> <b>StudentID:</b>[1.1.1.1] <br /><br />
hakre
  • 193,403
  • 52
  • 435
  • 836
webdev.gk
  • 209
  • 1
  • 4
  • 10
  • what i did is to str_replace on all html tags to remove it then i run preg_match('/\[(.*)?\]\s+/') to parse within inside [] but cannot get accurate data. any suggestions? thanks – webdev.gk Mar 21 '12 at 04:29

1 Answers1

1

You should be able to use the DOMDocument extension to parse the HTML.

Having said that, your snippet does not look very semantic at all, so perhaps regex might be a better option.

See this question for a comprehensive example on how to parse it with DOMDocument.

Community
  • 1
  • 1
F21
  • 32,163
  • 26
  • 99
  • 170