Title: PHP string manipulation
Last modified: August 18, 2016

---

# PHP string manipulation

 *  [waraxe](https://wordpress.org/support/users/waraxe/)
 * (@waraxe)
 * [20 years, 5 months ago](https://wordpress.org/support/topic/php-string-manipulation/)
 * Okay, here’a good one to test the PHP coders amoung us.
 * I want to read $post_content from a post and display only a portion of it if 
   it exceeds a certain length (we’ll say 1000 characters). But, I’m freaked out
   about just using this: echo(substr($post_content,0,999)); …because I don’t want
   it to cut off in the middle of an xhtml tag (or something equally error promising).
 * I had thought about iterating through $page_content and counting the ‘<‘ and ‘
   >’ (much like a running stack variable or counting 10’s in Black Jack)… but I
   still may end up cutting off before a beginning tag has goten to its ending tag.
 * Any ideas?

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Kafkaesqui](https://wordpress.org/support/users/kafkaesqui/)
 * (@kafkaesqui)
 * [20 years, 5 months ago](https://wordpress.org/support/topic/php-string-manipulation/#post-310350)
 * My the_excerpt Reloaded plugin makes use of WP’s pre-existing function balanceTags().
   If it helps:
 * [http://guff.szub.net/source/the-excerpt-reloaded.php](http://guff.szub.net/source/the-excerpt-reloaded.php)
 *  Thread Starter [waraxe](https://wordpress.org/support/users/waraxe/)
 * (@waraxe)
 * [20 years, 5 months ago](https://wordpress.org/support/topic/php-string-manipulation/#post-310355)
 * Yeah… I think that’ll do the trick. I’ll let everyone know what it looks like
   when I’m done. 🙂
 * Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘PHP string manipulation’ is closed to new replies.

## Tags

 * [Parsing](https://wordpress.org/support/topic-tag/parsing/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [strings](https://wordpress.org/support/topic-tag/strings/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [waraxe](https://wordpress.org/support/users/waraxe/)
 * Last activity: [20 years, 5 months ago](https://wordpress.org/support/topic/php-string-manipulation/#post-310355)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
