Copy link to clipboard
Copied
Hi all -
I need some help with this one. I'm writing a script that pretty much parses out the header and footer of a saved HTML document, so I only have the middle of it (its a quote file), and then resaves it as a new file. The header parsing (left) works perfectly, but when I get to the footer (right), it rips out everything EXCEPT for the header for some reason! So I end up getting a file that is more or less the header and the footer, but not the meat of the quote file.
Here's my code:
<!---read file --->
<cffile action="read" file="#filestoragelocation#/#cffile.serverFile#" variable="quotecontent">
<!---remove header --->
<cffile action="read" file="#templatelocation#/remove1.html" variable="bannerold">
<!---add new header --->
<cffile action="read" file="#templatelocation#/add1-1.html" variable="bannernew">
<!---replace data --->
<cfset quoteedit=Replace(quotecontent, LEFT(quotecontent,find(bannerold,quotecontent)), bannernew)>
<!--bannerdone--->
<!---update footer --->
<cffile action="read" file="#templatelocation#/remove2.html" variable="oldfooter">
<cffile action="read" file="#templatelocation#/add2w.html" variable="newfooter">
<cfset quoteedit=Replace(quoteedit, RIGHT(quoteedit,find(oldfooter,quoteedit)), newfooter)>
<!---<cfset quoteedit=Replace(quoteedit, oldfooter, newfooter)>--->
<!---write file --->
<cffile action="write" file="#filestoragelocation#/M#cffile.serverFile#" output="#quoteedit#">
So pretty much what I've done with BannerOld and OldFooter is found a tag in the code that is only in the document once (with the banner, its an image, with the footer, its text ("The terms and conditions of the CO")...and hypothetically, with left, I should be selecting everything up to the image in the banner and replacing it, and with right, I should be selecting everything after the text and replacing it.
For whatever reason, instead, I'm just getting the new banner and the footer in the final document. If I remove the footer code, it works perfectly (with of course, the old footer still being there).
I'm probably just having some dumb oversight here...but some help would be amazing. Thanks as always guys!!
JE
You say the first part is working so I will take your word for that, although it doesn't look right.
The second part need probably isn't working because youre calculating the Right X chars but you are counting the chars by finding the index of your find from the beginning. So imagine you are replacing the first 10 chars with your new header. Your doc is 100 chars total. You wnat to replace the last 10 characters. Your find returns 90 because you started from the beginning. You grab the Right
...Copy link to clipboard
Copied
You might try simplifying your code. Just get the quote portion of the file then add your header and footer around it.
Something like:<!--- original file --->
Copy link to clipboard
Copied
Hey there Bob -
Thanks for the response...unfortunately...the Old Header and Old Footers can change dynamically because they're from a 3rd party website...so what i've tried to do is grab pieces of the formatting...because that rarely changes...that terminates the header and starts the footer...and then use left and right to capture the rest of the header and footer. Does that make sense? And the rest of the header and footer has information that may or may not stay consistent. So unfortunately, its not as black and white as just selecting all of the header and footer and replacing them.
Thanks for giving it a shot though! My code is really close...its just something about the logic is slightly off with the footer.
Thanks!
JE
Copy link to clipboard
Copied
anyone?
Copy link to clipboard
Copied
Perhaps you could post some basic examples of the files you are working with so that we can re-create the problem you are having?
Copy link to clipboard
Copied
You say the first part is working so I will take your word for that, although it doesn't look right.
The second part need probably isn't working because youre calculating the Right X chars but you are counting the chars by finding the index of your find from the beginning. So imagine you are replacing the first 10 chars with your new header. Your doc is 100 chars total. You wnat to replace the last 10 characters. Your find returns 90 because you started from the beginning. You grab the Right 90 chars, taking you to the end of the header, and you are replacing all that with the footer.
What you want is Replace(quoteedit, RIGHT(quoteedit,Len(quoteedit)-find(oldfooter,quoteedit)), newfooter). That should work.
Copy link to clipboard
Copied
Ahhh you're right! Didn't stop to think about where the count was counting from. Thanks so much for the help!