• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How can I change my code so it displays the first 200 characters of text?

Guest
Apr 07, 2014 Apr 07, 2014

Copy link to clipboard

Copied

Hi. I'm teaching myself ColdFushion.  I'm creating a page to show a list of news articles. I want to show the first 200 characters of the text. I store my data (article content as text) in mySQL. Everyone works except that it's not displaying the first 200 characters of the text. It displays about 30 characters. I've been looking at my code for a long time and tried the "rereplace" method but it doesn't work. Can someone give me a hint on what's missing? Thanks a lot!

<!DOCTYPE html>

<html>

  <head>

                    <title>Assessment Project</title>

  <meta charset="UTF-8">

  </head>

  <body>

  <!--- Page Title --->

                    <h3>Article Listings</h3>

  <!--- Page Content --->

  <!--- Display article title, author, date, first 200 characters

                    of the article content and a link to view the full article --->

  <div align="left">

  <cfoutput query="myQuery1">

  <b><a href="full_article_view.cfm?ID=#article_ID#" style="color:##000000; text-decoration: none;">#ucase(myquery1.article_title)#</a></b>

                                        <hr>

                                        <p style="color:##848181; font-size:12px">#myquery1.article_author# :: #myquery1.article_date#</p>

                                        <cfset nonhtml=reReplace(myquery1.article_content, "<[^>]*>,[[:space:]]","","ALL")>

                                        #LEFT(nonhtml, 200)# ... <a href="full_article_view.cfm?ID=#article_ID#">Read More</a>

                                        #len(LEFT(nonhtml,300))#

  <br><br><br>

  </cfoutput>

  </div>

  </body>

</html>


Views

358

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 07, 2014 Apr 07, 2014

Copy link to clipboard

Copied

Have you tried to <cfdump> the query to make sure the content you are getting back is what you expect?  Then, <cfdump> your "nonhtml" variable to see if the reReplace() chopping out more content than you think it should.  What is this line displaying for you:

#len(LEFT(nonhtml,300))#

How many characters does it say you have?

-Carl V.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 07, 2014 Apr 07, 2014

Copy link to clipboard

Copied

It says I have 200 characters.  Sorry, I changed 300 to 200.

<cfdump> shows that my "nonhtml" variable still has the whole content.  the reReplace() did not chop out anything.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 08, 2014 Apr 08, 2014

Copy link to clipboard

Copied

LATEST

Cyu504 wrote:

<cfdump> shows that my "nonhtml" variable still has the whole content.  the reReplace() did not chop out anything.

The regular expression <[^>]*>,[[:space:]] looks odd. What do you wish to match?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation