if you do not have nested >
and <
, then you can try the following to match occurences:
$matches = array();
preg_match_all('/<([\s\S]*?)>/s', $string, $matches);
Try for yourserlf here. Note the ?
in the query which makes the match in parentheses ungreedy.
You can find an answer to a similar question here on SO.
If you want to strip away the values, then use preg_replace_callback
:
<?php
$string = '<p>This is a paragraph with <strong>bold</strong> text<p>';
echo "$string <br />";
$string = preg_replace_callback(
'/<([\s\S]*?)>/s',
function ($matches) {
// do whatever you need with $matches here, e.g. save it somewhere
return '';
},
$string
);
echo $string;
?>