Here is one of most powerful and used regular expression which was used by every developer once in their life for sure.
How to select content or string inside a HTML tag using regular expression in all languages.
I am sharing this regular expression with you. This regular expression is useful when you fetching content from Other Website using cURL.
]*>(.*?)'.$tag.'>} ?>
Here is one small example:
//Example to get text inside given tag
$content = file_get_contents("http://www.example.com");
$tag= 'h1'; //we will extract page heading
preg_match("{<'.$tag.'[^>]*>(.*?)'.$tag.'>}", $content, $match);
$data = $match[0];
echo $data;
?>
Note: This only returns text(string or HTML) inside the Tag you have given. It doesn’t include that tag.
Place your comment