custus.de
E-Mail
Abonnieren
Empfehlen
Verfolgen

Wordpress PHP-Code optimieren

24.08.2006 custus Kategorie: PHP, Wordpress Kommentare (0)

Ich habe mich etwas mit dem PHP-Code von Wordpress beschäftigt, um die Performance ein wenig zu steigern, obwohl bei wenig Traffic auf der Seite die Performance noch ok ist.
Hier ist die der verbesserte Code der Funktion wptexturize die in wp_includes/functions-formatting.php zu finden ist.
Update: Die Anpassung bezieht sich noch auf Wordpress 2.3 und wird inzwischen überholt sein.Und entschuldigt die Darstellung, mein CSS streikt im Moment etwas.

function wptexturize($text)
{
$output = ”;
// Capture tags and everything inside them
$textarr = preg_split(“/(<.*>)/Us”, $text, -1, PREG_SPLIT_DELIM_CAPTURE);
$stop = count($textarr);
$next = true; // loop stuff
for ($i = 0; $i < $stop; $i++)
{
$curl = $textarr[$i];
if (isset($curl{0}) && ‘<’ != $curl{0} && $next)
{ // If it’s not a tag
// static strings
$static_char1 = array(‘—’, ‘ — ‘, ‘–’, ‘xn–’, ‘…’, ‘“’, “””);
$static_repl1 = array(‘—’, ‘ — ‘, ‘–’, ‘xn--’, ‘…’, ‘“’, ‘”’);
$curl = str_replace($static_char1, $static_repl1, $curl);

// This is a hack, look at this more later. It works pretty well though.
$cockney = array(“’tain’t”, “’twere”, “’twas”, “’tis”, “’twill”, “’til”, “’bout”, “’nuff”, “’round”, “’cause”);
$cockneyreplace = array(“’tain’t”, “’twere”,”’twas”, “’tis”,”’twill”,”’til”,”’bout”, “’nuff”,”’round”,”’cause”);
$curl = str_replace($cockney, $cockneyreplace, $curl);
$dynamic_chars = array(“/’s/”, “/’(dd(?:’|’)?s)/”, ‘/(s|A|”)’/', ‘/(d+)”/’, “/(d+)’/”, “/(S)’([^'s])/”, ‘/(s|A)”(?!s)/’, ‘/”(s|S|Z)/’, “/’([s.]|Z)/”, “/ ™/i”);
$dynamic_repl = array(‘’s’, “’$1″, ‘$1‘’, ‘$1″’, ‘$1′’, “$1’$2″, ‘$1“$2′, ‘”$1′, ‘’$1′, ‘ ™’);
$curl = preg_replace($dynamic_chars, $dynamic_repl, $curl);
}
elseif (strstr($curl, ‘
{
// strstr is fast
$next = false;
}
else
{
$next = true;
}
$curl = preg_replace(‘/&([^#])(?![a-zA-Z1-4]{1,8};)/’, ‘&$1′, $curl);
$output .= $curl;
}
return $output;
}

Kommentare

Einen Kommentar schreiben




CAPTCHA-Bild CAPTCHA Audio
Bild neuladen