PHP to get content between in html tag

by Subramanian 2014-05-03 18:04:24

PHP to get content between in html tag:

The below php function is used to get the content between html tags.
For Example :
if the original string is like, "This is <b>GvSubhu</b>" then get the value in "b" tag.

function getTextBetweenTags($string, $tagname) {
$pattern = "/<$tagname ?.*>(.*)/";
preg_match($pattern, $string, $matches);
return $matches[1];
}
echo getTextBetweenTags("This is <b>GvSubhu</b>", b);


Output :
GvSubhu
124
like
0
dislike
0
mail
flag

You must LOGIN to add comments
hioxd

Good one....