note 107082 added to function.str-word-count
| From: | SamerAta at osu1 dot php dot net | Date: | Thu, 05 Jan 2012 17:21:23 +0000 |
| Subject: | note 107082 added to function.str-word-count | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-185377@lists.php.net to get a copy of this message | ||
This is my own version of to get SEO meta description from wordpress post content. it is also
generic usage function to get the first n words from a string.
<?php
function my_meta_description($text,$n=10)
{
$text=strip_tags($text); // not neccssary for none HTML
// $text=strip_shortcodes($text); // uncomment only inside wordpress system
$text = trim(preg_replace("/\s+/"," ",$text));
$word_array = explode(" ", $text);
if (count($word_array) <= $n)
return implode(" ",$word_array);
else
{
$text='';
foreach ($word_array as $length=>$word)
{
$text.=$word ;
if($length==$n) break;
else $text.=" ";
}
}
return $text;
?>
----
Server IP: 69.147.83.197
Probable Submitter: 109.224.43.193
----
Manual Page -- http://www.php.net/manual/en/function.str-word-count.php
Edit -- https://master.php.net/note/edit/107082
Del: integrated -- https://master.php.net/note/delete/107082/integrated
Del: useless -- https://master.php.net/note/delete/107082/useless
Del: bad code -- https://master.php.net/note/delete/107082/bad+code
Del: spam -- https://master.php.net/note/delete/107082/spam
Del: non-english -- https://master.php.net/note/delete/107082/non-english
Del: in docs -- https://master.php.net/note/delete/107082/in+docs
Del: other reasons-- https://master.php.net/note/delete/107082
Reject -- https://master.php.net/note/reject/107082
Search -- https://master.php.net/manage/user-notes.php