- PHP SmartyPants 1.5.1f (12 Kb)
- Latest version of PHP SmartyPants, released on January 23, 2013.
- PHP SmartyPants Typographer 1.0.1 (15 Kb)
- An extension to SmartyPants with extra features. See the full description of Typographer for details. Released on January 23, 2013.
PHP SmartyPants is a port to PHP of the original SmartyPants written in Perl by John Gruber.
PHP SmartyPants is a free web publishing tool that translates plain ASCII punctuation characters into “smart” typographic punctuation HTML entities.
SmartyPants can perform the following transformations:
- Straight quotes (
') into “curly” quote HTML entities
- Backticks-style quotes (
``like this'') into “curly” quote HTML entities
- Dashes (“
--” and “
---” into en- and em-dash entities
- Three consecutive dots (“
...” into an ellipsis entity
SmartyPants does not modify characters within
<script> tag blocks. Typically, these tags are used to display text where smart quotes and other “smart punctuation” would not be appropriate, such as source code or example markup.
For more details, read the SmartyPants home page.
PHP 4.0.5 or later
PHP SmartyPants works with WordPress, version 1.2 or later.
WordPress already includes a filter called “Texturize” with the same goal as SmartyPants. You could still find some usefulness to PHP SmartyPants if you are not happy enough with the standard algorithm.
To use PHP SmartyPants with WordPress, place the “smartypants.php” file in the “plugins” folder. This folder is hidden inside “wp-content” at the root of your site:
Activate the plugin with the administrative interface of WordPress. In the “Plugins” section you will now find SmartyPants. To activate the plugin, click on the “Activate” button on the same line than SmartyPants. Your entries will now be filtered by PHP SmartyPants.
Note: It is not possible at this time to apply a different set of filters to different entries. All your entries will be filtered by PHP SmartyPants if the plugin is active.
In your programs
You can use PHP SmartyPants easily in your current PHP program. Simply include the file and then call the SmartyPants function on the text you want to convert:
include_once "smartypants.php"; $my_text = SmartyPants($my_text);
If your program use the Smarty template engine, PHP SmartyPants can now be used as a modifier for your templates. Rename “smartypants.php” to “modifier.smartypants.php” and put it in your smarty plugins folder.
To file bug reports or feature requests (other than topics listed in the Algorithmic Shortcomings on John’s SmartyPants page) please send email to:
If the bug involves quotes being curled the wrong way, please send example text to illustrate.
PHP port by Michel Fortin.
Original Perl version of SmartyPants from John Gruber.
Portions of this program are based on Brad Choate’s nifty MTRegex plug-in.
Copyright and License
Copyright (c) 2004-2013 Michel Fortin All rights reserved.
Based on SmartyPants
Copyright (c) 2003-2004 John Gruber
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name “SmartyPants” nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
This software is provided by the copyright holders and contributors “as is” and any express or implied warranties, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. In no event shall the copyright owner or contributors be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage.