Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
Smarty SEO URL Friendly Modifier

 
Post new topic   Reply to topic    Smarty Forum Index -> Plugins
View previous topic :: View next topic  
Author Message
sangprabv
Smarty Rookie


Joined: 14 Feb 2005
Posts: 8
Location: Jakarta

PostPosted: Wed Aug 21, 2013 2:21 am    Post subject: Smarty SEO URL Friendly Modifier Reply with quote

The modifier:
Code:
<?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage PluginsModifier
 */

/**
 * Smarty SEO URL Friendly modifier plugin
 *
 * Type:     modifier<br>
 * Name:     seo<br>
 * Purpose:  SEO URL Friendly
 *
 * @link http://smarty.php.net/manual/en/language.modifier.seo.php replace (Smarty online manual)
 * @author Willy Mularto <me at sangprabv dot web dot id>
 * @param string $string  input string
 * @param string $search  text to search for
 * @param string $delimiter replacement text
 * @param string $case uppercase/lowercase/ucfirst
 * @return string
 */
function smarty_modifier_seo($string, $search, $delimiter, $case)
{
   /*Replace any non latin chars*/
   $string = iconv('UTF-8', 'ASCII//TRANSLIT', $string);
    /*Remove any non alpha numeric*/
    $string = preg_replace("/[^a-zA-Z 0-9]+/", " ",$string);   
    /*Remove any double delimiter*/
    $string = preg_replace("/[[:blank:]]+/", "$delimiter",$string);
    /*Remove any delimiter at the beginning of string if any*/
    $string = ltrim($string, "$delimiter");
    /*Remove any delimiter at the end of string if any*/
    $string = rtrim($string, "$delimiter");
   
    switch($case) {
       case 'upper':
          return strtoupper($string);
       case 'lower':
          return strtolower($string);
       case 'first':
          return ucfirst($string);
       default:
          return($string);
    }
}

?>

Save as modifier.seo.php and store it in plugins folder
Call it on your template page, here is the example:
{-$title|seo:" ":"-":"first"-}
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
Robins133
Smarty n00b


Joined: 29 Aug 2013
Posts: 1

PostPosted: Thu Aug 29, 2013 10:25 am    Post subject: Smarty SEO URL Friendly Modifier Reply with quote

Very nice one. This modifier may help my development cum seo friend.
He was asked before few hours and got this through Google.

Thank You Google and Smarty Forum..
Back to top
View user's profile Send private message
charleshbrenner
Smarty n00b


Joined: 27 Sep 2013
Posts: 1

PostPosted: Sat Sep 28, 2013 6:14 am    Post subject: Reply with quote

Hey I am new to SEO and did not get this completely. Can you please describe me what exactly its use is? This code looks very useful for SEO services for my company. What this plugin is used for? I would be very thankful to you if you can explain me in detail. Thank you well in advance for this. Smile
Visit:
seo consultancy | website logo design
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Plugins All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP