<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>Snipplr</title>
    <description>Recent snippets posted on Snipplr.com</description>
    <link>https://snipplr.com/</link>
    <lastBuildDate>Tue, 09 Jun 2026 22:31:40 +0000</lastBuildDate>
    <item>
      <title>(PHP) PHP Truncate function - Admiral</title>
      <link>https://snipplr.com/view/20726/php-truncate-function</link>
      <description>&lt;p&gt;Hey everyone, I was noticing that there are a lot of ways that people are using to write their own string truncation functions wit the use of other functions like 'substr_replace', but it kinda seemed like a lot of them went a bit too far out to make any sense to a n00b. Not that I am one anymore, but I though I'd add a note on this topic myself, in hopes that it might help others understand things a little better.&#13;
&#13;
Here's a concept that some people don't know about, or remember to use often enough; You can actually pull individual characters out of a string by referencing that string as though it were an array. Example: If I have the string $s = 'cat', I can use $s[0] to actually get out only the first character of that string, 'c'. I use that same principle below, but I just use a loop to iterate through a string and add the characters to the output variable one by one until the $lenth param has been reached, or until the end of the string.&#13;
&#13;
I hope this can help someone out!&#13;
&#13;
-Admiral Potato&lt;/p&gt;</description>
      <pubDate>Tue, 06 Oct 2009 14:49:00 UTC</pubDate>
      <guid>https://snipplr.com/view/20726/php-truncate-function</guid>
    </item>
  </channel>
</rss>
