Extracting text between body tags

Discuss PHP code and website development using PHP. Ask for help in PHP and Share information on php topics.

Extracting text between body tags

New postby Suji on Fri Nov 06, 2009 5:06 pm

how can i extract all text in html page between the <body> </body> tags ?
Suji
Newbee
Newbee
 
Posts: 35
Joined: Thu Sep 27, 2007 3:52 pm


Re: Extracting text between body tags

New postby nirmala on Sat Nov 07, 2009 11:10 am

Hi...
Try this code.
Code: Select all
<?php
$txt = file_get_contents($url);

$arr = get_tag($txt, "body");

print_r($arr);

function get_tag($txt,$tag){
$offset = 0;
$start_tag = "<".$tag;
$end_tag = "</".$tag.">";
$arr = array();
do{
$pos = strpos($txt,$start_tag,$offset);
if($pos){
$str_pos = strpos($txt,">",$pos)+1;
$end_pos = strpos($txt,$end_tag,$str_pos);
$len = $end_pos - $str_pos;
$f_text = substr($txt,$str_pos,$len);

$arr[] = $f_text;
$offset = $end_pos;
}
}while($pos);
return $arr;

}
?>
nirmala
Enthusiast
Enthusiast
 
Posts: 299
Joined: Fri Feb 29, 2008 3:38 pm


Return to PHP Topics

Who is online

Users browsing this forum: No registered users and 1 guest