<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sean&#039;s Blog &#187; relative links</title>
	<atom:link href="http://seanbehan.com/tag/relative-links/feed/" rel="self" type="application/rss+xml" />
	<link>http://seanbehan.com</link>
	<description>Web Programming, Ruby on Rails, Wordpress, PHP from Burlington, Vermont</description>
	<lastBuildDate>Wed, 18 Jan 2012 21:44:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Absolutize Relative Links Using PHP and Preg_Replace_Callback</title>
		<link>http://seanbehan.com/php/absolutize-relative-links-using-php-and-preg_replace_callback/</link>
		<comments>http://seanbehan.com/php/absolutize-relative-links-using-php-and-preg_replace_callback/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 17:29:41 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[absolute links]]></category>
		<category><![CDATA[file_get_contents]]></category>
		<category><![CDATA[preg_replace_callback]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[relative links]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=727</guid>
		<description><![CDATA[I was in the market for a simple php script to replace hrefs with their absolute paths from scraped web pages. I wrote one myself. I used the preg_replace_callback function so that I could pass the parsed results as a single variable. &#38;lt;?php $domain = &#34;http://seanbehan.com&#34;; $pattern = &#34;/\bhref=[\&#34;&#124;'](.*?)[\&#34;&#124;']/&#34;; $string = file_get_contents($domain); // prepends relative [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Fphp%2Fabsolutize-relative-links-using-php-and-preg_replace_callback%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Absolutize Relative Links Using PHP and Preg_Replace_Callback" data-url="http://seanbehan.com/php/absolutize-relative-links-using-php-and-preg_replace_callback/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>I was in the market for a simple php script to replace hrefs with their absolute paths from scraped web pages. I  wrote one myself. I used the preg_replace_callback function so that I could pass the parsed results as a single variable.</p>
<pre class="wp-code-highlight prettyprint">
&amp;lt;?php
$domain = &quot;http://seanbehan.com&quot;;
$pattern = &quot;/\bhref=[\&quot;|'](.*?)[\&quot;|']/&quot;;
$string = file_get_contents($domain);

// prepends relative links w/ $domain skips returns the match if already absolute
function replace_href($match){
  global $domain;
  if(substr($match[1], 0, 7)!==&quot;http://&quot; &amp;&amp; substr($match[1],0,8)!==&quot;https://&quot;){
    return &quot;href='&quot;.$domain.$match[1].&quot;'&quot;;
  } else {
    return &quot;href='&quot;.$match[1].&quot;'s&quot;;
  }
}
print preg_replace_callback($pattern, &quot;replace_href&quot;, $string);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/php/absolutize-relative-links-using-php-and-preg_replace_callback/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

