Skip to main content
Known Participant
March 19, 2009
Answered

Output first 250 characters of html file

  • March 19, 2009
  • 1 reply
  • 338 views
Does anyone know how to output the first 250 characters of an html file.
I am using a cfinclude to output the file but sometimes the html is really long and there are other things on the page. I would like to limit the html file to a certain amount of characters and give the user an option to read the rest.
An example but this doesn't work would be <cfinclude template="#left(file.htm, 250)#">. I know that does not work but it would if the information were in a database.

Any suggestions?
Thanks
    This topic has been closed for replies.
    Correct answer Newsgroup_User
    <cfsavecontent variable="mytext">
    <cfinclude template="somepage.cfm">
    </cfsavecontent>
    <cfoutput>#left(mytext, 250)#</cfoutput>

    you may also want to strip all html tags out of the mytext var in order
    not to have cf cut it in the middle of some tag and render it in the output:
    <cfoutput>
    #left(trim(rereplace(mytext, "<[^>]*>", "", "all")), 250)#
    </cfoutput>

    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/

    1 reply

    Newsgroup_UserCorrect answer
    Inspiring
    March 19, 2009
    <cfsavecontent variable="mytext">
    <cfinclude template="somepage.cfm">
    </cfsavecontent>
    <cfoutput>#left(mytext, 250)#</cfoutput>

    you may also want to strip all html tags out of the mytext var in order
    not to have cf cut it in the middle of some tag and render it in the output:
    <cfoutput>
    #left(trim(rereplace(mytext, "<[^>]*>", "", "all")), 250)#
    </cfoutput>

    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/