Miles Johnson // Blog: 5 custom PHP functions: Strings. All of these functions can be found within the Titon Utility library.
It's now time for some PHP that isn't Cake related. This is the first part in a series of "Basic/Common PHP functions that all programmers should know". This series has to deal with manipulating strings. I try to make my functions short, sweet and powerful, and I hope you learn something from them. Truncate This function takes a long string and shortens it to a defined length and adds appends an ellipsis (or custom string) to the end.
Public function truncate($text, $limit = 25, $ending = '...') { if (strlen($text) > $limit) { $text = strip_tags($text); $text = substr($text, 0, $limit); $text = substr($text, 0, -(strlen(strrchr($text, ' ')))); $text = $text . Shorten This function works similarly to truncate(), but instead of chopping off the end of the string, it chops out the middle. Obfuscate Now this function doesn't directly scramble the text and confuse the user, instead it scrambles the source code. Slugify Listing. TCPDF - PHP Class for PDF. It appears that you are using AdBlocking software.
The cost of running this website is covered by advertisements. If you like it please feel free to a small amount of money to secure the future of this website. <div style="font-family:helvetica,arial;font-size:small;padding:0 4px 0 4px;background-color:#FFFFCC;color:#003399;border:1px;border-style:solid;border-width:1px;border-color:orange;"><form action=" method="post"><div><input type="hidden" name="cmd" value="_donations" /><input type="hidden" name="business" value="paypal@tecnick.com" /><input type="hidden" name="lc" value="US" /><input type="hidden" name="item_name" value="Tecnick.com" /><input type="hidden" name="no_note" value="0" /><input type="hidden" name="currency_code" value="GBP" /><input type="hidden" name="bn" value="PP-DonationsBF:btn_donate_SM.gif:NonHostedGuest" /> It appears that you are using AdBlocking software.
The cost of running this website is covered by advertisements. PHP class for generating PDF documents. Akelos PHP Framework. Simple Layouts with PHP. This tutorial is for those starting out in PHP and want to learn a great way to create layouts.
This will help reduce redundancy and keep you from writing too much code. Download the Source Anyone that has been developing HTML based sites for some time has undoubtedly ran in to the issue of keeping the design consistent across multiple pages. Most websites follow a similar layout to the picture. This is great unless you have sites that require multiple pages. Technique #1 A lot of sites follow this kind of layout scheme The first technique is the entry level solution that works across nearly all situations. <! Take out everything up to the point and put that in a new file called head.php. <? Now just put whatever HTML/PHP content you want in between those two include statements and check it out in a browser. It may be easier to think of it as a puzzle, you are piecing together a complete HTML page with includes. Technique #2 Alright we have that under our belt let’s look at another solution. <! Quick and Dirty PHP Caching.
Advertisement Caching your database-driven website pages has a plethora of benefits, not the least of which being improved speed and reduced server loads.
This article will explain how to set up a simple caching system, and will also address when and where caching might not be appropriate. For me, the impetus to switch to a caching method for one of my database driven sites was sparked by Mosso, since they bill by cpu cycle, and I have one site that is, well, humongous (60k+ pages), and it happens to the highest traffic site on the account. While the database queries were all very efficient, and each page had, on average, no more than 6 queries, performance and cpu cycles would both be helped quite a lot by implementing a cache.
This caching solution was a temporary fix, while we switched to a new CMS that was already using a robust caching system. Using output buffering, caching pages is incredibly easy. The basic stuff. 40+ Invaluable PHP Tutorials and Resources. SocialEngine PHP Social Network Script - Create your own social media community! A PHP Charting library. PHP snippets. 43 Ways to Optimize your PHP Code.