试图找出正则表达式给我一个大脑抽筋:)
我正在href使用允许我在内容上运行正则表达式的插件,用WordPress帖子内容中的单个短代码替换数千个单独的链接.
我不是尝试将SQL查询与RegEx结合起来,而是分两个阶段进行:首先是SQL查找/替换每个单独的URL到单个短代码,第二个阶段,删除其余的'href`链接标记.
这些是我从第一步开始就拥有的一些例子; 如您所见,URL已被[nggallery id=xxx]短代码替换.
<a href="[nggallery id=xx]"><span class="shutterset">
<img class="alignnone size-large wp-image-23067" title="Image Title"
src="http://example.com/wp-content/uploads/2015/06/image-title.jpg"
alt="" width="685" height="456" /></span></a>
<a href="[nggallery id=xxxxx]">Click here!</a>
<a title="title title" href="[nggallery id=xxx]" target="_blank">Title Link Title Link</a>
Run Code Online (Sandbox Code Playgroud)
现在,我需要删除前导和结尾之间的所有href链接标记 - span,img等等,只留下短代码.<a</a>[nggallery id=xxx]
我从这里开始:https://www.regex101.com/r/rL8wP1/2
但我不知道如何防止[nggallery id=xxx]在RegEx中捕获短代码.
2015年7月9日更新
@ nhahtdh的答案看起来工作得很完美,不是太贪心,也不会吃邻近的html链接.使用(和)作为分隔符,并$1替换为WordPress中的正则表达式插件.(如果使用BBEdit,则需要使用\1)
( <a\s[^>]*"(\[nggallery[^\]]*\])".*?<\/a> )
Run Code Online (Sandbox Code Playgroud)
2015年7月2日更新
感谢Fab Sa (下面的回答),他的正则表达式在https://www.regex101.com/r/rL8wP1/4
<a.*(\[nggallery[^\]+]*\]).*?<\/a>
Run Code Online (Sandbox Code Playgroud)
在regex101模拟器中工作,但是当在BBEdit文本编辑器或运行正则表达式的WordPress插件中使用时,他的正则表达式会删除 …
每次在jQuery Tabs UI中有标签更改时,我都会使用下面的函数在#quotescontainer中显示随机引用.除了IE7-8(当然)以外的一切都可以正常工作.
IE7-8中发生的情况是显示第一个引号,第二个随机引用出现在第一个引号正下方的#quotescontainer中.在所有其他浏览器中,只显示一个引号,并在选项卡更改时轮换.因此,IE从quotes.html获取div.quote中的第一个引用,显示它并在第一个引号下面显示随机引用.
我可以尝试强制IE正确交换引号?而不是第一次引用"卡住"?
这是缓存问题吗?或者函数的问题总是读取quote1并在其下面附加quote2?
我没有在.htaccess中使用缓存.我试过添加$.ajaxSetup({cache: false});功能没有运气.
6/01/11修复; 问题是<div class="quote">quote text</div>在quotes.html中的一些html .不知何故,这打破了IE7-8.
jsfiddle: http ://jsfiddle.net/YAEe5/28/
我的职责: 在Matthew Ratzloff的帮助下
select: function(event, ui) {
var random = Math.floor(Math.random() * (Math.pow(2, 32) - 1));
$('div#quotescontainer').load('http://mydomain.com/quotes.html?' + random, function() {
var quotes = $(this).find('div.quote');
var index = Math.floor(Math.random() * quotes.length);
quotes.hide().eq(index).fadeIn();
});
Run Code Online (Sandbox Code Playgroud)
引号显示在页面上#quotescontainer
quotes.html包含:
<div class="quote">Quote1</div>
<div class="quote">Quote2</div>
<div class="quote">Quote3</div>
Run Code Online (Sandbox Code Playgroud) 在Serverfault上有这个问题几天没有运气.
我在VPS上运行了mysqltuner.pl,对于要更改的变量的建议有很多问题.我确信这些都是复杂答案的一般性问题.
我不知道如何编写查询并对服务器进行测试,但我只是试图从服务器中获得更多性能,该服务器运行五个WordPress站点,每月页面查看次数超过200,000次.
我已经通过phpmyadmin优化了数据库(并定期这样做),但调谐器仍然说有碎片表.因为这是WordPress,我无法在核心代码中更改查询.
但是我应该增加多少变量,如query_cache_size和innodb_buffer_pool_size?其他innodb变量怎么样?
my.cnf中不存在一些建议的变量,如table_cache,并在调谐器报告等中标记.我可以将它们添加到my.cnf吗?
(为什么这个块在my.cnf中重复?我可以删除副本吗?)
Run Code Online (Sandbox Code Playgroud)set-variable = innodb_buffer_pool_size=2M set-variable = innodb_additional_mem_pool_size=500K set-variable = innodb_log_buffer_size=500K set-variable = innodb_thread_concurrency=2
下面是my.cnf和mysqltuner的输出:
my.cnf的内容:
query-cache-type = 1
query-cache-size = 8M
set-variable=local-infile=0
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
old_passwords=1
skip-bdb
set-variable = innodb_buffer_pool_size=2M
set-variable = innodb_additional_mem_pool_size=500K
set-variable = innodb_log_buffer_size=500K
set-variable = innodb_thread_concurrency=2
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
skip-bdb
set-variable = innodb_buffer_pool_size=2M
set-variable = innodb_additional_mem_pool_size=500K
set-variable = innodb_log_buffer_size=500K
set-variable = innodb_thread_concurrency=2
Run Code Online (Sandbox Code Playgroud)
mysqltuner的输出:
------- General Statistics --------------------------------------------------
[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.0.45 …Run Code Online (Sandbox Code Playgroud) 我不太了解javascript来弄清楚为什么这个脚本中以"window.open ..."开头的行在IE7-8-9b中抛出了无效的参数错误.在Firefox和Webkit中运行良好.
(该脚本onclick="share.fb()"使用html链接进行调用,并弹出一个新的浏览器窗口以在FB和Twitter上共享).
var share = {
fb:function(title,url) {
this.share('http://www.facebook.com/sharer.php?u=##URL##&t=##TITLE##',title,url);
},
tw:function(title,url) {
this.share('http://twitter.com/home?status=##URL##+##TITLE##',title,url);
},
share:function(tpl,title,url) {
if(!url) url = encodeURIComponent(window.location);
if(!title) title = encodeURIComponent(document.title);
tpl = tpl.replace("##URL##",url);
tpl = tpl.replace("##TITLE##",title);
window.open(tpl,"sharewindow"+tpl.substr(6,15),"width=640,height=480");
}
};
Run Code Online (Sandbox Code Playgroud) 所以我在我的网站.htaccess文件中有这个,以防止来自所有其他域的图像,JS和CSS的热链接.
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain\.com [NC]
RewriteRule \.(gif|jpe?g|js|css)$ - [F,NC,L]
Run Code Online (Sandbox Code Playgroud)
问题:如何有选择地允许一个或两个域进行热链接?
今天我检查wordpress数据库的表,但我找不到关键表的外键,任何人都可以告诉我为什么wordpress没有外键?
我在下面有jQuery .slideUp和.slideDown函数,当到达#showfootershop浏览器窗口底部的div时,#footershopdiv会向上滑动,然后立即向下滑动.
如何在浏览器窗口底部#footershop保持"向上"和可见状态#showfootershop,并且在用户向上滚动浏览器窗口之前不能向下滑动?
小提琴: http ://jsfiddle.net/8PUa9/1/
jQuery的:
$(window).scroll(function(){
/* when reaching the element with id "showfootershop" we want to
show the slidebox. */
var distanceTop = $('#showfootershop').offset().top - $(window).height();
if ($(window).scrollTop() > distanceTop)
$("#footershop").slideUp();
else
$("#footershop").slideDown();
});
Run Code Online (Sandbox Code Playgroud)
页脚中的html:
<div id="showfootershop"></div>
<div id="footershop">
<h1>Shop Links</h1>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
CSS:
#footershop {
height:35px;
width:100%;
display: none;
z-index: 2;
}
Run Code Online (Sandbox Code Playgroud) Javascript和jQuery(Fancybox)问题
我正在使用下面的Javascript函数进行Twitter共享(以及其他服务;功能代码简化为仅针对此问题的Twitter),它抓取要共享的页面URL和标题,并在链接中调用的onclick.这导致Twitter共享页面在弹出的浏览器窗口中加载,即<img src="/images/twitter_16.png" onclick="share.tw()" />
为了与网站的其他设计方面保持一致,我希望能够做的是让Twitter共享页面不在标准浏览器窗口中打开,而是在Fancybox(jQuery)窗口中打开.
当img或href链接class="iframe"在链接和标题中的文档就绪函数中包含类(在本例中)时,Fancybox可以在iFrame中加载外部页面.
现在,当然,当我将iframe类提供给也具有的iframe类时onclick share.tw(),我得到两个弹出窗口:一个浏览器窗口弹出窗口,其中加载了正确的Twitter共享页面,以及一个显示站点404的Fancybox jQuery弹出窗口.
如何更改功能以使用Fancybox呈现Twitter共享页面?这是接近它的正确方法吗?或者有更好的方法,比如在jQuery中实现共享功能呢?
谢谢...
Javascript共享功能:
var share = {
tw:function(title,url) {
this.share('http://twitter.com/home?status=##URL##+##TITLE##',title,url);
},
share:function(tpl,title,url) {
if(!url) url = encodeURIComponent(window.location);
if(!title) title = encodeURIComponent(document.title);
tpl = tpl.replace("##URL##",url);
tpl = tpl.replace("##TITLE##",title);
window.open(tpl,"sharewindow"+tpl.substr(6,15),"width=640,height=480");
}
};
Run Code Online (Sandbox Code Playgroud)
它被调用,即: <img src="/images/twitter_16.png" onclick="share.tw()" />
Fancybox函数,通过添加class="iframe"img或href链接调用
$(".iframe").fancybox({
'width' : '100%',
'height' : '100%',
'autoScale' : false,
'transitionIn' : 'none',
'transitionOut' : 'none',
'type' : 'iframe'
});
Run Code Online (Sandbox Code Playgroud) 我有一个奇怪的问题可能与jQuery文档准备好有关.下面是一个包含常用社交网络脚本的html和脚本块.下面的Javascript块dd_outer在body div的左边缘显示div,当浏览器窗口缩小时,div淡出并且dd_footerdiv被淡入.两个div之间的淡入淡出和淡出效果正常.
问题有两个:一个问题是当浏览器窗口是全宽(1200px +)时,Facebook脚本将无法加载并始终显示; 它有时会出现,有时则不会出现,有时会在页面重新加载后出现,有时则不会出现.(不涉及浏览器或.htaccess缓存).只有Facebook的份额不能始终如一地显示; 所有其他服务显示确定.
第二个问题是,当浏览器窗口很窄时 - 650 px左右,当dd_outerdiv没有显示且dd_footerdiv为 - 页脚div将不会显示在页面重新加载,直到浏览器窗口移动最小量.然后div将显示,Facebook分享和所有.对于移动设备,这是一个问题,因为浏览器窗口将开始变窄并且不应该被"轻推"以进行dd_footerdiv显示.
这个问题可能已经发挥作用,因为我已经从WordPress插件中调整了这个代码,该插件使用选项来设置dd_outerdiv 的位置和滚动高度.这就是文档就绪调用之上的变量的原因.
这是一个似乎是文档准备问题的问题吗?
如何将变量集成到脚本本身?它们是否被硬编码并不重要; 我可以在需要时更换它们.
我会把它扔进一个jsfiddle来演示但是div不会在窗口调整大小的情况下实际浮动.
为清晰起见,我没有包含CSS.
这是html和社交脚本块:
<div class='dd_outer'><div class='dd_inner'><div id='dd_ajax_float'>
<div class="sbutton"><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like layout="box_count" show_faces="false" font=""></fb:like></div>
<div class="sbutton">
<a href="http://twitter.com/share" class="twitter-share-button" data-url="" data-count="vertical" data-via="#">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div>
<div class="sbutton"><script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script><g:plusone size="tall"></g:plusone></div>
<div class="sbutton"><script src="http://platform.linkedin.com/in.js" type="text/javascript"></script>
<script type="IN/Share" data-counter="top"></script></div>
</div></div></div>
Run Code Online (Sandbox Code Playgroud)
在页脚中 <div id="dd_footer">that contains the same social scripts as above</div> ,并且通过以下脚本淡入淡出: …
我的jQuery函数生成的动画很不稳定,我一直在寻找不同的SO解决方案,例如添加jquery.easing,但没有运气.问题是每个div中的iframe吗?
关于如何平滑动画的任何想法?我的基本切换功能是最好的方法吗?
JSFiddle: http ://jsfiddle.net/gwLcD/8/
基本标记在下面,并在页面上重复多次(每个"录像带"div之间有文本块):
<div class="videotoggle">
<p><h2 class="entry-title">View a few minutes of the (title) video </h2></p>
<div class="videoblock">
<iframe width="560" height="315" src="http://www.youtube.com/embed/????????"
frameborder="0" allowfullscreen></iframe>
</div></div>
Run Code Online (Sandbox Code Playgroud)
功能:
$(document).ready(function(){
$(".videoblock").hide(); //closes all divs on first page load
$(".entry-title").click(function() {
$this = $(this); //this next code only allows one open div at a time
$content = $this.closest('.videotoggle').find(".videoblock");
if (!$this.is('.active-title')) {
$('.active-title').removeClass('active-title');
$this.addClass('active-title');
$(".videoblock:visible").slideToggle(400); //slide toggle
$content.slideToggle(400);
}
});
});
Run Code Online (Sandbox Code Playgroud) jquery ×5
javascript ×4
mysql ×2
wordpress ×2
.htaccess ×1
fancybox ×1
hotlinking ×1
html ×1
html-parsing ×1
jquery-ui ×1
mod-rewrite ×1
performance ×1
regex ×1
removeclass ×1
slidedown ×1
slidetoggle ×1
slideup ×1
sql ×1