Last active
August 29, 2015 14:05
-
-
Save leobossmann/5a4c2ae2bb1556f5237f to your computer and use it in GitHub Desktop.
Regex for getting usable info out of typo3's crummy <link> tags
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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