-1

i have some html like this

<span itemprop="actor" itemscope="" itemtype="http://schema.org/Person"><a rel="nofollow" href="/ru/name/shameik-moore" itemprop="url"><span itemprop="name">Шамеик Мур</span></a></span>

and i need to insert img tag inside link before inner span tag like this

<span itemprop="actor" itemscope="" itemtype="http://schema.org/Person"><a rel="nofollow" href="/ru/name/shameik-moore" itemprop="url"><img src="/photo/00/04/20/42074.jpg"><span itemprop="name">Шамеик Мур</span></a></span>

im trying the php code

$img = '<img src="/photo/00/04/20/42074.jpg">';
$actor = preg_replace('|(<a.*?>)|', '$1'.$img, $it);

but in result i have this

<span itemprop="actor" itemscope="" itemtype="http://schema.org/Person"><img src="/photo/00/04/20/42074.jpg"><span itemprop="name">Шамеик Мур</span></a></span>

where i lost my first tag here? )) please help with my reg_replace expression

web user
  • 137
  • 1
  • 3
  • 11

1 Answers1

1

Here you go.

$img = '<img src="/photo/00/04/20/42074.jpg">';
$actor = preg_replace('/(<a\b[^<]*>)/', '$1$img', $it);
NeerPatel
  • 863
  • 6
  • 19