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

Limit character count on Master Page?

New Here ,
Apr 17, 2009 Apr 17, 2009

Copy link to clipboard

Copied

language: php

Question: In regards to the master page, does anyone know how to limit the character count to only display 250 in Dreamweaver CS4?

TOPICS
Server side applications

Views

1.6K

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

correct answers 1 Correct answer

LEGEND , Apr 20, 2009 Apr 20, 2009

That's easily fixed. Use this custom function instead:

function extractChars($text, $chars = 250) {
     if (strlen($text) < $chars) {
          return $text;
     } else {
          $pos = strpos($text, ' ', $chars);
          return substr($text, 0, $pos) . '...';
     }
}

Put that function definition in your page, and use it like this:

echo extractChars($row_recordsetName['fieldName']);

If the text is less than 250 characters, you'll just get the full text. If it's more than 250, you get the text shorte

...

Votes

Translate

Translate
LEGEND ,
Apr 17, 2009 Apr 17, 2009

Copy link to clipboard

Copied

What do you mean by "master page"? Are you trying to limit the number of characters that can be inserted into a text area? Or do you want to limit the number of characters displayed when retrieving a record from a database?

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
New Here ,
Apr 17, 2009 Apr 17, 2009

Copy link to clipboard

Copied

I want to limit the number of characters displayed when retrieving a record from a database.

jeff

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
Enthusiast ,
Apr 17, 2009 Apr 17, 2009

Copy link to clipboard

Copied

Depends on what server language you are using. In CF it would be something like this...

<cfoutput>#Left(Recordset.FieldName, 250)#</cfoutput>

Lawrence   *Adobe Community Expert*
www.Cartweaver.com
Complete Shopping Cart Application for
Dreamweaver, available in ASP, PHP and CF

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
New Here ,
Apr 17, 2009 Apr 17, 2009

Copy link to clipboard

Copied

I"m using php for my language.

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
Engaged ,
Apr 17, 2009 Apr 17, 2009

Copy link to clipboard

Copied

Hi Flyboy,

Here is a link to look over the function:  http://us3.php.net/manual/en/function.substr.php

$string = $row_Recordset['dbfield'];

$output = substr($string, 0, 255);


echo $output;

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
LEGEND ,
Apr 18, 2009 Apr 18, 2009

Copy link to clipboard

Copied

Using substr() will definitely do it, but it will cut off the string at exactly the number of characters entered as the third argument. A more elegant way of doing it is to find the first space after 250 characters, and then add an elipsis like this:

$string = $row_recordsetName['fieldName'];

// get the first space after 250 characters

$space = strpos($string, ' ', 250);

// cut off the string at the space and add an ellipsis
echo substr($string, 0, $space) . '...';

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
New Here ,
Apr 20, 2009 Apr 20, 2009

Copy link to clipboard

Copied

hmm, let me try. I will keep you posted.

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
New Here ,
Apr 20, 2009 Apr 20, 2009

Copy link to clipboard

Copied

Ahh, it worked.  However, i did notice that if there are less than 250 characters in that database table an error message will appear on that line (see below).

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
LEGEND ,
Apr 20, 2009 Apr 20, 2009

Copy link to clipboard

Copied

That's easily fixed. Use this custom function instead:

function extractChars($text, $chars = 250) {
     if (strlen($text) < $chars) {
          return $text;
     } else {
          $pos = strpos($text, ' ', $chars);
          return substr($text, 0, $pos) . '...';
     }
}

Put that function definition in your page, and use it like this:

echo extractChars($row_recordsetName['fieldName']);

If the text is less than 250 characters, you'll just get the full text. If it's more than 250, you get the text shortened.

The function has an optional second argument, which determines the number of characters that you want to use as the limit. So, if you want only the first hundred, do this:

echo extractChars($row_recordsetName['fieldName'], 100);

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
New Here ,
Apr 20, 2009 Apr 20, 2009

Copy link to clipboard

Copied

LATEST

Sweet!

Thanks..

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