Saludos Señores!
Estoy teniendo problemas con mi código PHP. La idea es que los posts de mi página web generen una URL amigable para los buscadores de forma automática. No obstante, el código que utilizo ahora mismo no elimina artículos, preposiciones o acentos de las palabras.
Quiero que haga lo siguiente:
Título: Con orgullo y pasión se puede conseguir cualquier cosa
URL: orgullo-pasion-puede-conseguir-cualquier-cosa
A continuación os pongo el código PHP:
<?php
if (!defined('BASE_URL')) {
exit ('No direct script access allowed');
}
/**
*--------------------------------------------------------------------------
* === CLASS SOLUTIISOFT ===
*--------------------------------------------------------------------------
* Collection of static methods helpful
*
* PHP version 5.3
*
* @category E-Blog
* @package Core
* @subpackage Libraries
* @filename solutiisoft.php
* @author Solutii Soft <[email protected]>
* @copyright 2013 Solutii Soft
* @license 2013 Solutii Soft
* @link http://www.eblog.solutiisoft.com
* @since File available since Release 1.0
*/
class Solutii_Soft
{
/**
* Create a friendly URL
*
* @param string $str URL which need to be transform
*
* @function friendlyURL
* @access public
* @return string
*/
public static function friendlyURL($str)
{
$delimiter = '-';
$clean = iconv('UTF-8', 'ASCII//TRANSLIT', $str);
$clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean);
$clean = strtolower(trim($clean, '-'));
$clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean);
return $clean;
}
/**
* All characters in the string after the last _, if these numbers will be deleted
*
* @param string $string string which need to be transform
*
* @function slugURL
* @access public
* @return string
*/
public static function slugURL($string)
{
$url = explode('-', $string);
if (is_numeric(end($url))) {
end($url);
unset($url[key($url)]);
}
return self::friendlyURL(implode('-', $url));
}
/**
* Clean all spaces before and after the comma
*
* @param string $string string which need to be transform
*
* @function prepareTags
* @access public
* @return string
*/
public static function prepareTags($string)
{
return implode(",", preg_split('~,\s*~', trim($string)));
}
/**
* One-way string hashing
*
* @param string $string string which need to be hash
*
* @function hashPassword
* @access public
* @return hashed string
*/
public static function hashPassword($string)
{
global $_EBLOG_hash;
$salt = $_EBLOG_hash['salt'];
$strength = "12";
if (CRYPT_BLOWFISH == 1) {
$presalt = (version_compare(PHP_VERSION, '5.3.7', '<')) ? '2a' : '2y';
$blowfish_salt = '$'. $presalt .'$' . $strength . '$'. substr($salt, 0, CRYPT_SALT_LENGTH) .'$';
return crypt($string, $blowfish_salt);
}
return sha1(hash_hmac('sha512', $salt, $string));
}
/**
* Remove all malicious code (better known as XSS)
*
* @param string $dirty_html string that need to be clean
*
* @function cleanXSS
* access public
* @return string
*/
public static function cleanXSS($dirty_html)
{
include_once 'public/vendor/htmlpurifier/htmlpurifier.standalone.php';
$config = HTMLPurifier_Config::createDefault();
$purifier = new HTMLPurifier($config);
return $purifier->purify($dirty_html);
}
/**
* Check if an array is empty
*
* @param array $array array which need to be check
*
* @function isEmptyArray
* @access public
* @return true for empty or false otherwise
*/
public static function isEmptyArray($array)
{
if (array_filter($_FILES['image']['name']) === array()) {
return true;
}
return false;
}
/**
* Remove all characters up to the first _ including this
*
* @param string $imageName name of image
*
* @function altOfImage
* @access public
* @return string
*/
public static function altOfImage($imageName)
{
$name = explode('_', pathinfo($imageName, PATHINFO_FILENAME));
unset($name[0]);
return implode(' ', $name);
}
}
/* end of file solutiisoft.php */
A ver si a alguno de vosotros se os ocurre como arreglarlo para que elimine los artículos, preposiciones y acentos (pero no el carácter acentuado, solo el acento).
Edito: adjunto el archivo .php http://ge.tt/5Nlo6e72/v/0?c