I have to collect some data from a website.My data is wrapped as div s.Inside each div there is a title tag.I need to get the text inside these title tags.How to do this. I have written the following code.What modification I have to apply for acheiving the task
<?php
$str = '';
$page = file_get_contents('http://www.sarkari-naukri.in/');
$dom = new DOMDocument();
$dom->loadHTML($page);
$divs = $dom->getElementsByTagName('div');
$i = 0;
$len = $divs->length;
while($i<$len) {
$div = $divs->item($i++);
$id = $div->getAttribute('id');
if(strpos($id,'post-') !== false ) {
// i need to get text inside title tag inside this div
$title ='';//title should be stored here
$str = $str.$title;
}
}
echo $str;
SAMPLE HTML
<body>
<div id = 'post-1'>
<title>title 1</title>
</div>
<div id = 'post-2'>
<title>title 2</title>
</div>
<div id = 'post-3'>
<title>title 3</title>
</div>
</body>