Function to fetch data between two tags/delimiters

Your rating: None Average: 4.3 (4 votes)

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

?>
 #

Thanks a lot, this is function which I was hunting

 

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.

Cumulus Tag Cloud

Kiran Says

SEO Architect,SEO Specialist reflect my values.

By enduring black hat methods the SEO industry is setting itself up for washout and sleepwalking into oblivion.

Jobs in India