Help - Search - Members - Calendar
Full Version: How to extract URL from HTML link?
Movable Type Community Forum > Additional Resources > Tips and Tricks
richarderiksson
Long story short, I have weblog entries that consist solely of the following:
CODE
<a href="http://www.foo.com/">Foo</a>

...and would like to make an RSS feed of this weblog. The <link> tag needs to contain only the URL in the weblog entry, not the HTML. In other words, I need regex (or some other method) to have <$MTEntryBody$> output only:
CODE
http://www.foo.com/

Can this be done using the MTRegex plugin?
gvtexas
I did something similar when creating my mobile index template: http://www.inkmuse.com/imblog/mindex.html so I know it can be done. I used the Collect plug-in to make it work (with a lot of help from Kevin!). Code I used was this:

CODE
<MTCollect tags="a">
 <b><font color="#770077"><$MTEntryTitle upper_case="1"$></font></b><br>
 <MTCollectThis show="1" a="/ \[[href]\]">
  <$MTEntryBody$>
 <$MTEntryMore$>
</MTCollectThis>
</MTCollect>


...but in my case, as you see in the link, I wanted the hyperlink to stay in place followed by the url in brackets. In fumbling with this, I was able to get only the url to show without being a hyperlink, but didn't want to keep it that way. So you might start with Kevin's Collect plugin.

Cheers,
Gary
richarderiksson
With the help of Adam, here's the code I'm using:
CODE
<MTAddRegex>s|<a href=\"(.*)\">(.*)</a>|$1|g</MTAddRegex>

Later on, in the RSS feed, there's this MT tag:
CODE
<MTEntryBody regex="1">

Thanks Adam!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.