<?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 Behan&#039;s Web Development Portfolio and Blog &#187; absolute links</title>
	<atom:link href="http://seanbehan.com/tag/absolute-links/feed/" rel="self" type="application/rss+xml" />
	<link>http://seanbehan.com</link>
	<description>Web Development, Wordpress, Moodle, Ruby on Rails and Design in Burlington, Vermont</description>
	<lastBuildDate>Fri, 30 Jul 2010 17:17:12 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<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>admin</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. 

&#60;?php
$domain = "http://seanbehan.com";
$pattern = "/\bhref=[\"&#124;'](.*?)[\"&#124;']/";
$string = file_get_contents($domain);

// prepends relative links w/ $domain [...]


Related posts:<ol><li><a href='http://seanbehan.com/programming/parse-for-links-with-prototype-js/' rel='bookmark' title='Permanent Link: Parse for Links with Prototype JS'>Parse for Links with Prototype JS</a></li>
<li><a href='http://seanbehan.com/programming/how-to-importexport-your-wordpress-blogroll-er-your-links/' rel='bookmark' title='Permanent Link: How to Import/Export Your Wordpress Blogroll&#8230; er, Your Links'>How to Import/Export Your Wordpress Blogroll&#8230; er, Your Links</a></li>
<li><a href='http://seanbehan.com/programming/offset-an-element-with-relative-position-property-without-taking-up-any-space-in-document/' rel='bookmark' title='Permanent Link: Offset an Element with Relative Position Property with CSS Without Taking Up Any Space in the Document'>Offset an Element with Relative Position Property with CSS Without Taking Up Any Space in the Document</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<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>
&lt;?php
$domain = "http://seanbehan.com";
$pattern = "/\bhref=[\"|'](.*?)[\"|']/";
$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)!=="http://" &#038;&#038; substr($match[1],0,8)!=="https://"){
    return "href='".$domain.$match[1]."'";
  } else {
    return "href='".$match[1]."'s";
  }
}
print preg_replace_callback($pattern, "replace_href", $string);
</pre>


<p>Related posts:<ol><li><a href='http://seanbehan.com/programming/parse-for-links-with-prototype-js/' rel='bookmark' title='Permanent Link: Parse for Links with Prototype JS'>Parse for Links with Prototype JS</a></li>
<li><a href='http://seanbehan.com/programming/how-to-importexport-your-wordpress-blogroll-er-your-links/' rel='bookmark' title='Permanent Link: How to Import/Export Your Wordpress Blogroll&#8230; er, Your Links'>How to Import/Export Your Wordpress Blogroll&#8230; er, Your Links</a></li>
<li><a href='http://seanbehan.com/programming/offset-an-element-with-relative-position-property-without-taking-up-any-space-in-document/' rel='bookmark' title='Permanent Link: Offset an Element with Relative Position Property with CSS Without Taking Up Any Space in the Document'>Offset an Element with Relative Position Property with CSS Without Taking Up Any Space in the Document</a></li>
</ol></p>]]></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>
