There is a dynamic link

<a href="http адрес динамический" target="_blank">динамическое содержимое</a> 

It would be necessary that only the 'dynamic content' would remain

 $html_links = preg_replace('"\b(https?://\S+)"', '', $text); 

remains

  <a href=" target="_blank">динамическое содержимое</a> 

Help to win regexp, I do not understand anything in it.

  • Need to extract <a> </a> tag content? - koks_rs
  • I don’t need the link inside; just what would be 'dynamic content' left - Nickolay S.
  • If you have only one tag in your line, you can make it much simpler: echo strip_tags("<a href='link' target='_blank'>динамическое содержимое</a>"); - koks_rs
  • Use strip_tags : $content = strip_tags($s); - Wiktor Stribiżew

3 answers 3

 $html_links = preg_replace('#<(/?)a\b.*?>#', '<$1span>', $text); 

    To capture text between <a></a> tags, use the group (.+) . To replace the entire line with the text of the first group, use $1 in the replace-parameter.

     $text = '<a href="http адрес динамический" target="_blank">динамическое содержимое</a>'; $txt = preg_replace("/<a.+>(.+)<\/a>/", "$1", $text); 

    as a result, the variable $txt will be set to динамическое содержимое .

    In general, you will achieve the same result using the strip_tags() function:

     $txt = strip_tags($text, "a") 
       $text = '<a href="http адрес динамический" target="_blank">динамическое содержимое</a>'; preg_match_all('/<a href.*">(.*)<\/a>/', $text, $html_links); print_r($html_links); 
      • did you check the code? - teran
      • now working :)) - L. Vadim