- rtrim: documentation ( source)
- preg_replace_callback: documentation ( source)
- print_r: documentation ( source)
- explode: documentation ( source)
- preg_split: documentation ( source)
<?php
$attributes = array();
$htmlcontent = '<img alt="" src="{assets_2100:{filedir_12}HappyDog.jpg}" style="height:400px; width:100px">';
preg_replace_callback('/src=(\'|")(.*?)\1/', function($matches) use ($attributes) {
global $attributes;
$terms = preg_split('/\{|\}/', $matches[2], -1, PREG_SPLIT_NO_EMPTY);
foreach($terms as $key => $term) {
if($key != (count($terms) - 1)) {
$params = explode('_', $term);
$attributes['data-' . rtrim($params[0], ':')] = $params[1];
} else {
$attributes['src'] = 'uploads/' . $term;
}
}
}, $htmlcontent);
print_r($attributes);