";
// Time the preg_match way
$time_a1 = microtime( true );
echo "Start preg_match: $time_a1
";
// The real work
$filtered = null;
for ( $i = 0; $i < $repeat; $i++ ){
$filtered .= content( $content );
}
// Timing output
$time_a2 = microtime( true );
echo "End preg_match: $time_a2
";
echo "Total time: " . 1000 * ( $time_a2 - $time_a1 ) . " milliseconds
";
echo "Time per execution: " . 1000 * ( ( $time_a2 - $time_a1 ) / $repeat ) . " milliseconds
";
echo "Original
" . $content;
echo "
";
echo "Filtered
" . $filtered;
// -- Plugin Stubs--------------------------------------------------------------
// From SEO Auto Linker, http://wordpress.org/extend/plugins/seo-auto-linker/
// -----------------------------------------------------------------------------
function content( $content ) {
$header_replacements = array();
$link_replacements = array();
$other_replacements = array();
$shortcode_replacements = array();
$filtered = $content;
preg_match_all( '/' . get_shortcode_regex() . '/', $filtered, $scodes );
if( ! empty( $scodes[0] ) ) {
$shortcode_replacements = gen_replacements( $scodes[0], 'shortcode' );
$filtered = replace( $shortcode_replacements, $filtered );
}
preg_match_all( '/]*>.+?<\/h[1-6]>/iu', $filtered, $headers );
if( ! empty( $headers[0] ) ) {
$header_replacements = gen_replacements( $headers[0], 'header' );
$filtered = replace( $header_replacements, $filtered );
}
preg_match_all( '/<(img|input)(.*?) \/?>/iu', $filtered, $others );
if( ! empty( $others[0] ) ) {
$other_replacements = gen_replacements( $others[0], 'others' );
$filtered = replace( $other_replacements, $filtered );
}
// Not using Links post types, build here
preg_match_all(
'/(.*?)<\/a>/iu',
$filtered,
$links
);
if( ! empty( $links[0] ) ) {
$start = count( $link_replacements );
$tmp = gen_replacements( $links[0], 'links', $start );
$filtered = replace( $tmp, $filtered );
$link_replacements = array_merge(
$link_replacements,
$tmp
);
}
$regex = get_kw_regex();
$url = 'http://www.danielbachhuber.com';
$max = 1;
if( ! $regex || !$url || !$max )
continue;
$target = '_self';
$filtered = preg_replace(
$regex,
'$1$2$3',
$filtered,
absint( $max )
);
return $filtered;
}
function replace( $arr, $content ) {
return str_replace(
array_values( $arr ),
array_keys( $arr ),
$content
);
}
function gen_replacements( $arr, $key, $start = 0 ) {
$hash = md5( 'seo-auto-linker' );
$rv = array();
$h = $hash;
foreach( $arr as $a ) {
$rv[""] = $a;
$start++;
}
return $rv;
}
function get_kw_regex() {
$keywords = array(
'wordpress',
'post',
'url',
'test',
'image',
'hello',
'world',
'WordPress',
'code',
'git'
);
return sprintf( '/(\b)(%s)(\b)/ui', implode( '|', $keywords ) );
}