Home » » Get text between two strings in php

Get text between two strings in php

Written By Unknown on Sabtu, 25 Februari 2012 | 23.55

A little but useful function to get text between two specified strings.

It takes three parameters. The source, start and end. And returns the text between start and end delimeters.

  function between($src,$start,$end){
$txt=explode($start,$src);
$txt2=explode($end,$txt[1]);
return trim($txt2[0]);
}


Example

$str="This is my content from which i want to fetch a block of text between two delimeters. Note that it returns only the first match";

echo between($str, "my", "returns");
Share this article :

Posting Komentar

 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. Kumpulan Kata Broadcast Blackberry - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger