Skip to content

Instantly share code, notes, and snippets.

@leobossmann
Last active August 29, 2015 14:05
Show Gist options
  • Save leobossmann/5a4c2ae2bb1556f5237f to your computer and use it in GitHub Desktop.
Save leobossmann/5a4c2ae2bb1556f5237f to your computer and use it in GitHub Desktop.
Regex for getting usable info out of typo3's crummy <link> tags
typo3's link tags are formatted like this:
<link url target css-class title-attribute>Linktext</link>
to get all vital info, use this regex:
<link\s(\S+)[^"]*(?:"([^"]+)")?>([^<>]+)<\/link>
PHP to convert this to markdown and replace the wonderfully helpful default title:
$bodytext = preg_replace('/<link\s(\S+)[^"]*(?:"([^"]+)")?>([^<>]+)<\/link>/', "[$3]($1 \"$2\")", $this->bodytext);
$bodytext = preg_replace('/\[([^\[\]]+)\]\((\S+)\s{1}\\"Opens external link in new window\\"\)/', "[$1]($2 \"$1\")", $bodytext);
$this->bodytext = trim(html_entity_decode(strip_tags($bodytext)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment