Submitted by Kiran on Mon, 01/12/2009 - 12:49
This is a simple PHP function which can fetch data between two tags/delimiters. Which is helpful if in case you want to crawl site for specific content.
<?php
function fetch_data($string, $start_tag, $end_tag){
$position = stripos($string, $start_tag);
$str = substr($string, $position);
$str_second = substr($str, strlen($start_tag));
$second_positon = stripos($str_second, $end_tag);
$str_third = substr($str_second, 0, $second_positon);
$fetch_data = trim($str_third);
return $fetch_data;
}
?>
Example is:
<?php
$string = 'I prefer PHP for web development';
$fetch_data = fetch_data($string, 'prefer', 'for');
echo $fetch_data;
//OUTPUT: PHP
?>
»
- 1271 reads













Thanks a lot, this is function which I was hunting
Post new comment