Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to capture page title from previous URL? 1

Status
Not open for further replies.

olchiik

Programmer
May 7, 2009
33
0
0
US
Hello,

I have this piece of code to capture page title, but it gives me an error... Please Help!

Code:

<cfoutput><input type="hidden" name="prevurl" value="#CGI.HTTP_REFERER#">
<table width="318" border="0" bgcolor="FFFFFF" align="center">
<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 ReReplaceNoCase(cfhttp.fileContent, ".*<title>([^<>]*)</title>.*", "\1")>
</cffunction>
<cfset refurl="#CGI.HTTP_REFERER#"></cfoutput>
<cfoutput>#getPageTitle("refurl")#</cfoutput>

Error is in this line:
<cfreturn ReReplaceNoCase(cfhttp.fileContent, ".*<title>([^<>]*)</title>.*", "\1")>....

Just in time compilation error

Invalid token found on line 93 at position 27.( open parentheses) ColdFusion was looking at the following text:(Invalid expression element. The usual cause of this error is a misspelling in the expression text.

The last successfully parsed CFML construct was a CFRETURN tag occupying document position
 
<cfhttp method="get" redirect="true" url="#CGI.HTTP_REFERER#" throwonerror="true"></cfhttp>
<cfoutput>#ReFindNoCase( ".*<title>([^<>]*)</title>.*", cfhttp.fileContent, 1, "true")#</cfoutput>

gave me

Error Diagnostic Information

Expression result cannot be converted to a string

Expressions used inside tags like CFOUTPUT, CFQUERY, CFMAIL, etc. must evaluate to a value that can be converted to a string for output or dynamic text accumulation purposes. Complex objects, such as queries, arrays, and COM/DCOM objects, cannot be represented as strings.

The error occurred while processing an element with a general identifier of (#ReFindNoCase( ".*.*", cfhttp.fileContent, 1, "true")#), occupying document position (9:11) to (9:87).


I am wandering...cfhttp.fileContent is "testing testing" and this is the text between <body></body>...does it look at <title> at all?
 
if ReFindNoCase ever returned 1 that means it FOUND what you were looking for. when you output cfhttp.fileContent look at the page source to see if the title tag is there... if it's not then something is wrong.

Travis Hawkins
jobs.bestcodingpractices.com
 
Yes, I can see title in source code.
Hmmm.... I guess I don't understand this functions enough to play with them in a right way
 
ok, first... you're just outputing the ReFindNoCase( ".*<title>([^<>]*)</title>.*", cfhttp.fileContent, 1, "true") ... it's returning a structure not a string.

second your RE string will match the whole page, everything before title and after title, including the title... that's everything.

try this:
Code:
<cfset st = REFindNoCase("<title>.*?</title>",cfhttp.fileContent,1,"True")>

<p>The value of st.pos[1] is: <cfoutput>#st.pos[1]#.</cfoutput></p>
<p>The value of st.len[1] is: <cfoutput>#st.len[1]#.</cfoutput></p>
<p>
<cfoutput>#mid(cfhttp.fileContent, st.pos[1], st.len[1])#</cfoutput>
</p>

That should tell you the start position and length, and output the entire title tag, then you just need to strip off the "<title>" start and end tags

Travis Hawkins
jobs.bestcodingpractices.com
 
it gave me the start position and length, but it didn't output the entire title tag

 
this is the output I get


The value of st.pos[1] is: 26.

The value of st.len[1] is: 27.
 
Oh...I got it...stupid me...
Thank you very very very very very very very much!!!!!!!!!!
 
tlhawkins ...yes, on this count I am very good! Thank you very much for being patient with me and helping me.

Now I am wrestling to remove those <title> and </title>
I did find the way to remove <title> not sure if it's essential to remove </title>. Because I removed beginning tag, page title appears anyway. I am just wandering if it will include end tag in DB... didn't test that yet.

Thanks again!

cfSearching thank you for your advise, I will check. However it is very unlikely there will be no referrer..this is for feedback form.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top