Please help, how to choose data between tags </a> and [/caption] ?

I have this code

 [caption id="attachment_10925" align="alignnone" width="580"]<a href=""><img class="size-full wp-image-10925" title="image title" src="" alt="" width="580" height="461" /></a> Текст который нужно выбрать[/caption] 
  • one
    preg_match_all("/<\/a>([^caption]*)\[\/caption\]/umi", $someBigTextForMatching, $out); echo '<pre>'; print_r($out[1]); echo '</pre>'; - Alexey Shimansky
  • Alas, but does not work: ( - akasergej
  • what exactly is not working? ideone.com/uO3y1R - Alexey Shimansky
  • oh sorry i'm fine thanks - akasergej
  • 2
    @ w3lifer yes, perhaps) probably it was necessary to have something like <\/a>(.*?)\[\/caption\] ..... although I see the answer to the similar written exactly - Alex Shimansky

1 answer 1

 <?php $str = '[caption id="attachment_10925" align="alignnone" width="580"]<a href=""><img class="size-full wp-image-10925" title="image title" src="" alt="" width="580" height="461" /></a> Текст который нужно выбрать[/caption]'; echo preg_replace( '=.*?\</a\>(.*?)\[/caption\].*?=s', '$1', $str ); 

http://sandbox.onlinephpfunctions.com/code/81e7bc661f79e173ec6c7fd8fc2f34e25d05a5eb

http://php.net/manual/ru/function.preg-replace.php