1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to limit characters please take a look

Discussion in 'PHP' started by a4tech, Mar 15, 2013.

  1. #1
    Hello, I am wanted to generate meta description. But when i use this I get the description out of limit. I am wanted to limit it to 255 characters or 25 words.

    Please tell me how can I make limit meta_description to # of words or characters.

                     
    array (
    '<meta name="description" content="' . stripslashes(html_entity_decode($var)) . '" />'
    );
    
    PHP:
    Thank You
     
    Solved! View solution.
    Last edited: Mar 15, 2013
    a4tech, Mar 15, 2013 IP
  2. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #2
    That depends on whether you want a usable description or not. If you chop off the description at 255 characters or 25 words, you may be left with a useless string. (IOW, your idea isn't well thought out.)
     
    Rukbat, Mar 15, 2013 IP
  3. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #4
    for the number of words I'd use a regex to split it apart into an array for length...
    http://www.php.net/manual/en/function.preg-match-all.php

    /\b[w+]\b/ would most likely do the job.

    Though I would NOT be doing it at the point of generating markup -- you should be doing that when the description is entered into a form and submitted to the database; that way you get a proper description that's within parameters and doesn't end up chopped off -- which is what Rukbat was raising a concern about.

    Though I'd probably limit it to 160 characters, since that's the actual limit most systems (like google) use on it.
     
    deathshadow, Mar 16, 2013 IP