I want to manipulate content
$description = 'Title <div data-type="page" data-id="1">Abcdef</div><div data-type="page" data-id="2">Fghij</div>';
I use preg_match to take value of data-type
& data-id
if (preg_match('/<div data-type="(.*?)" data-id="(.*?)">(.*?)<\/div>/s', $description) ) { ... }
Not so sure with this regex, i expected to get
array(0 => array('type' => 'page', 'id' => 1), 1 => array('type' => 'page', 'id' => 1))
And using function get_page_content($id)
to return real content by id, finally my content look like this : Title this is page id 1 this is page id 2
Solved: (Temporary)
$regex = '/<div data-type="(.*?)" data-id="(.*?)">(.*?)<\/div>/';
$description = 'Title <div data-type="page" data-id="1">Abcdef</div><div data-type="page" data-id="2">Fghij</div>';
echo preg_replace_callback(
$regex,
function($match) {
if (isset($match[1]) && isset($match[2])) {
if ($match[1] == 'page') {
return '<div class="page-embed">'. get_page_content($match[2]) .'</div>';
}
}
return false;
},
$description);