Pete Freitag Pete Freitag

Function to get Page Title from a URL

coldfusion

I wrote a simple function today that grabs a url, and parses out the title of the page from the url:

<cffunction name="getPageTitle" returntype="string" output="false">
	<cfargument name="pageurl" type="string" required="true">
	<cfhttp method="get" redirect="true" url="#arguments.pageurl#" throwonerror="true"></cfhttp>
	<cfreturn ReReplace(cfhttp.fileContent, ".*<title>([^<>]*)</title>.*", "\1")>
</cffunction>

<cfoutput>#getPageTitle("http://www.macromedia.com/")#</cfoutput>

Like this? Follow me ↯

Function to get Page Title from a URL was first published on March 23, 2005.

If you like reading about cfml, or regex then you might also like:

FuseGuard Web App Firewall for ColdFusion

The FuseGuard Web Application Firewall for ColdFusion & CFML is a high performance, customizable engine that blocks various attacks against your ColdFusion applications.

Comments

nice. You ought to submit it to cflib.org
by Ryan Guill on 03/23/2005 at 7:33:01 PM UTC
Hi there...

Copied and pasted this code block.

Have updated it to now return a complete anchor with href and title attributes.

Works like a charm.

Very inventive thinking. Will definitely come in handy at some point.

Cheers
by Ethan Cane on 03/27/2005 at 3:26:11 PM UTC
Nice active blog you have. You have some great reading here.
by Mortgage Leads on 02/11/2006 at 3:30:36 AM UTC
Great blog.
by Refinance Mortgage on 02/12/2006 at 10:14:35 PM UTC
I really enjoy reading your articles. Keep up the great work.
TBoardenson
by Tom on 03/06/2006 at 6:29:23 PM UTC
Domain for sale quality results found here
by accountingapp.net on 06/29/2006 at 1:46:26 AM UTC
are you looking for check advance in florida check this site. check advance in florida can be found here to help you get through to payday.
by florida check advance on 06/30/2006 at 4:57:35 PM UTC
Not secret that that that we search for, whereas you will not always
find on the first page of search engine.
But in other, although it rarely or in no way you use, this in sight.
Therefore you will focus attention on http://www.iknowall.com.
It searches for simultaneously in three largest bases of peace and issues results
at will - on one page or on the different.
Parsit'. is probable, also possible simultaneously all.

http://www.iknowall.com
by iknowall on 06/23/2007 at 5:02:40 AM UTC