php - mb_substr cutting off words in post excerpt? -


this code using show html formatting on wordpress post excerpts:

 function get_excerpt($post, $ln){         if (!empty($post->post_excerpt)) {             if (strlen($post->post_excerpt) > $ln) {                 echo mb_substr(($post->post_excerpt), 0, $ln);             }          } else {             if (strlen($post->post_content) > $ln) {                   echo mb_substr(($post->post_content), 0, $ln);             }          }      } 

how can edit mb_substr excerpt end @ period? instance, excerpt end "she has lovable , innocent charm tha" instead of "she has lovable , innocent charm keeps people caring her." want excerpt finish sentence , end in period instead of stopping @ character limit, set @ 800. in code $ln set 800.

update:

this code ended using. words still cut off in excerpt added read more link end dots.

 function get_excerpt($post, $ln){     if (!empty($post->post_excerpt)) {         if (strlen($post->post_excerpt) > $ln) {             echo mb_substr(($post->post_excerpt), 0, $ln) . '...'; ?> <a href="<?php echo get_permalink( $post -> id )?>">[read more]</a>  <?php }      } else {         if (strlen($post->post_content) > $ln) {               echo mb_substr(($post->post_content), 0, $ln) . '...';?> <a href="<?php echo get_permalink( $post -> id )?>">[read more]</a>  <?php }      }  } 

if can guarantee there "." in text can this:

echo strtok("lorem ipsum dolor sit amet, consectetur adipiscing elit. nam sit amet egestas lacus. maecenas posuere dolor vitae ultrices viverra.","."); 

this output: "lorem ipsum dolor sit amet, consectetur adipiscing elit"

strtok manual page


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -