How to change the href from links?

Tell me how to resolve this issue.
On the page there are links like:
<a href="#" data-page="[12,3]"></a>
<a href="#" data-page="[12,2]"></a>

You want to get the attribute data-page, process it and sootvestvenno to put in place of the href attribute.
July 9th 19 at 10:24
2 answers
July 9th 19 at 10:26
$pattern = '/data-(\w+)=/';
$string = '<strong class="annotate annotateSelected" data-pageid="1242799" data-start="80" data-end="86" data-canon="Season" data-toggle="tooltip" title="Season (SPORTS_OBJECT_EVENT)" data-placement="top" data-type="SPORTS_OBJECT_EVENT"><em>season</em></strong>';
$arr = array();
foreach($result[1] as $item){
 $pat = '/data'.$item.'="(?P<'.$item.'>\w+?)"/';

 preg_match($pat, $string, $res);
 $arr[$item] = $res[1];
echo print_r($arr);

 [pageid] => 1242799
 [start] => 80
 [end] => 86
 [canon] => Season
 [toggle] => tooltip
 [placement] => top
This method only works with one link, and I need to process all the links! - Lavonne_Cass commented on July 9th 19 at 10:29
July 9th 19 at 10:28
if you are using jquery:

$('a').each(function(i, a){
 $(a).attr('href', 'some ssilka'+$(a).attr('data-page'));

Find more questions by tags PHPRegular expressions