• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 573
  • Last Modified:

removing whitespace?

ok easy one, hope you can help, i have this in my code:

      <cfhttp method="get"
                  url="#productPageTemplate#?prodId=#FORM.prodId#">
            </cfhttp>
            <cfset productPageContent = #cfhttp.FileContent#>
            
            <cffile action="write"
                  output="#productPageContent#"
                  file="#productPageLocation#/#productPageName#.html"
                  nameconflict="overwrite">

now i want to remove all whitespace on the outputted file above, i spotted a post on here that use this: #reReplace(Content,"[[:space:]]{2,}","","ALL")# to remove whitespace, but i have tried using it on the above to no joy (no errors, just does nothing!) can anyone help or give me a way above to remove whitespace?

many thanks!
0
pigmentarts
Asked:
pigmentarts
  • 5
  • 5
  • 5
  • +1
2 Solutions
 
aseusaincCommented:
Are you sure the whitespace is TRUE whitespace?  Looks to me like you are retrieving HTML via cfhttp.  Is it possible that the source is filled with a bunch of &nbsp; and <br> ??
0
 
usachrisk1983Commented:
Can you post some expanded code, such as how you used rereplace?
0
 
pigmentartsAuthor Commented:
i am not using replace yet, i just wanted to know if it could be used.

anyway to answer the other questions i am using cfhttp to call my own coldfusion page and turn it into a static html page (but that not the problem), before its turned into a static page using the above i would like to remove all the true whitespace.


SOMEHWERE HERE REMOVE THE WHITESPACE BEFORE ITS TURNED INTO A STATIC PAGE.

 <cfhttp method="get"
               url="#productPageTemplate#?prodId=#FORM.prodId#">
          </cfhttp>
          <cfset productPageContent = #cfhttp.FileContent#>
         
          <cffile action="write"
               output="#productPageContent#"
               file="#productPageLocation#/#productPageName#.html"
               nameconflict="overwrite">
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
usachrisk1983Commented:
I can't validate your regex, but if it will in fact work, do something like:

<cfhttp method="get" url="#productPageTemplate#?prodId=#FORM.prodId#" />
<cfset variables.sHTTPData = CFHTTP.FileContent>
<cfset variables.sDataClean = reReplace(variables.sHTTPData,"[[:space:]]{2,}","","ALL")>    
<cffile action="write" output="#variables.sDataClean#" file="#productPageLocation#/#productPageName#.html" nameconflict="overwrite">

You could even turn the two CFSET lines into one, I'd probably keep them seperate to make my troubleshooting easier.
0
 
mkishlineCommented:
<cffile action="write"
    output="#REReplace(pageContent,'(&nbsp;{2,}|<br[\s\/]*>|\s+)',' ','all')#"
    file="#productPageLocation#/#productPageName#.html"
    nameconflict="overwrite">
0
 
aseusaincCommented:
0
 
aseusaincCommented:
I should clarify, that the above will surpress the whitespace thats generated by cfml parsing.  If the whitespace is something thats already in your source, the other suggestions for replace is probably the solution...
0
 
pigmentartsAuthor Commented:
dont think this would work mkishline,

 <cffile action="write"
    output="#REReplace(pageContent,'(&nbsp;{2,}|<br[\s\/]*>|\s+)',' ','all')#"
    file="#productPageLocation#/#productPageName#.html"
    nameconflict="overwrite">

becuase by this point is already been parsed here:

<cfhttp method="get"
                  url="#productPageTemplate#?prodId=#FORM.prodId#">
            </cfhttp>
            <cfset productPageContent = #cfhttp.FileContent#>


its at #cfhttp.FileContent# that is html, so its need to be some where in the 'write' maybe? i dont know?  
0
 
pigmentartsAuthor Commented:
maybe what usachrisk1983 has written but i can not get that to work?
0
 
pigmentartsAuthor Commented:
here is the full function:


<cffunction name="updateProduct" hint="update a product">

      <cfscript>
      if(not IsDefined('FORM.featured')) {
            FORM.featured = "off";
      }
      if(not IsDefined('FORM.projectpage')) {
            FORM.projectpage = "off";
      }
      if(not IsDefined('FORM.active')) {
            FORM.active = "off";
      }
      if (FORM.pageName IS NOT "") {
            productPageName = Replace(#FORM.pageName#," ","-","All");
      }
      else {
            productPageName = Replace(#FORM.name#," ","-","All");
      }
      </cfscript>
      
            <cfquery name="updateProduct" datasource="#dbSource#" username="#dbUsername#" password="#dbPassword#">
                  UPDATE products SET name = '#FORM.name#', productCode = '#FORM.productCode#', description = <cfqueryparam value="#Form.description#"  cfsqltype="CF_SQL_VARCHAR">, price = '#FORM.price#', retailPrice = '#FORM.retailPrice#', salePrice = '#FORM.salePrice#', pageName = '#productPageName#', metaKeywords = '#FORM.metaKeywords#', metaDescription = '#FORM.metaDescription#', featured = '#FORM.featured#', active = '#FORM.active#',  description2 = '#FORM.description2#', manId = '#FORM.manId#', idg = '#FORM.relat#', projectpage = '#FORM.projectpage#' WHERE prodId = '#FORM.prodId#'
            </cfquery>
            
            
            <!-- Delete old page if required -->
            <cfif NOT FORM.existingPageName IS #productPageName# AND fileExists('#productPageLocation##FORM.existingPageName#.cfm')>
                  <cffile action="delete"
                  file="#productPageLocation#/#existingPageName#.html">
            </cfif>
            
            <!-- Get and write page -->
            

            <cfhttp method="get"
                  url="#productPageTemplate#?prodId=#FORM.prodId#">
            </cfhttp>
            <cfset productPageContent = #cfhttp.FileContent#>
            
            <cffile action="write"
                  output="#productPageContent#"
                  file="#productPageLocation#/#productPageName#.html"
                  nameconflict="overwrite">

      <cfset Session.success = "You have successfully updated the product">
      
</cffunction>
0
 
usachrisk1983Commented:
Did you try my code pigmentarts?  Or mkishline's for that matter, since that's the same, but compressed even more down to one line.
0
 
usachrisk1983Commented:
Ignore my comment, I was typing as you were pasting.  Reading your entry now...
0
 
usachrisk1983Commented:
What doesn't work about my code?
0
 
pigmentartsAuthor Commented:
usachrisk1983, your code worked find, no problems, love it but i think it works too well now as the out putted html is all on one line, but ill open another post for that becuase its a different question.

thanks your guys you have been a big help1
0
 
aseusaincCommented:
Found this on the intarweb.  This guy has a few different ways he's stripping space.  The CRLF one is probably what you're looking for.

http://lists.evolt.org/archive/Week-of-Mon-20030224/135598.html

0
 
aseusaincCommented:
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 5
  • 5
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now