在我正在修改的Wordpress代码中遇到一行代码,我完全不知道2美元是多少$3是?也许这是我从未学过的PHP东西?有人能给我解释一下吗?
下面是我正在修改的插件:
<?php
/*
Plugin Name: Pinterest Plugin
Plugin URI: http://www.WordPressPinterestPlugin.com
Description: Display a Pinterest "Pin It" button on top of your images, only when people move their mouse over the image.
Version: 1.0
Author: Promotioner.com
Author URI: http://www.WordPressPinterestPlugin.com
/*============================================================================================================ */
class pin_success
{
function pin_success()
{
add_filter(\'the_content\', array(\'pin_success\', \'nosn_pinterest\'));
}
function nosn_pinterest($content) {
global $post;
$posturl = urlencode(get_permalink()); //Get the post URL
$pindiv = \'<div class="sn_pinterest">\';
$pinurl = \'<a href="http://pinterest.com/pin/create/button/?url=\'.$posturl.\'&media=\';
$pindescription = \'&description=\'.urlencode(get_the_title());
$pinfinish = \'" target="_blank" class="sn_pin"></a>\';
$pinend = \'</div>\';
$pattern = \'/<img(.*?)src="(.*?).(bmp|gif|jpeg|jpg|png)"(.*?) \\/>/i\';
$replacement = $pindiv.$pinurl.\'$2.$3\'.$pindescription.$pinfinish.\'<img$1src="$2.$3" $4 />\'.$pinend;
$content = preg_replace( $pattern, $replacement, $content );
return $content;
}
}
$successnexus = new pin_success;
wp_enqueue_style(\'sn_pinterest\', plugins_url(\'sn_pinterest.css\', __FILE__ ));
?>
最合适的回答,由SO网友:helgatheviking 整理而成
同意这不是一个真正的WordPress问题。
然而,我相信1美元、2美元和3美元是指由(.*)确定的捕获组通配符。现在,regex对我来说完全是巫毒,所以很抱歉,我不能百分之百地解释它。但是,如果查看$模式定义:
$pattern = \'/<img(.*?)src="(.*?).(bmp|gif|jpeg|jpg|png)"(.*?) \\/>/i\';
那么,开局后的第一场比赛就是1美元
<img
.
2美元是图像的src
属性
$3可能是src属性之后的任何东西
4美元在我看来并不明确