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
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.)
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.