-3

I want to replace tags in strings with preg_replace if there is a special attribute within the tag.

I want to replace

<link record:extend_events:6465 - internal-link><i>Some text</i></link>

into:

<a href="http://record?identifier=tx_extend_events&amp;event=6465"><i>Some text</i></a>

Link tags should be skipped if there is no attribute like "record:extend_events" in it e.c.:

<link http://www.stack.com - external-link>Some text</link>

prix
  • 1
  • 1
  • 1
  • 2
    [You shouldn't use regex to parse HTML](https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags). – GrumpyCrouton Nov 01 '17 at 18:50
  • Try to provide a [minimal complete example](https://stackoverflow.com/help/mcve) of what you have attempted thus far. It will help people try to answer your question – D Lowther Nov 01 '17 at 19:12

1 Answers1

0

I used the following code. Still a flaw but after cleaning the source a little bit up it should do the job. Probably it's helpful to someone.

preg_replace('#\<link record:extend_events:(.*) (.*)\s*>(.*)\</link\>#Uis', '<a href="http://record?identifier=tx_extend_events&amp;event=\1">\3</a>', $suchtext);
prix
  • 1
  • 1
  • 1