1
我需要獲取wordpress短代碼之間的內容。在短代碼之間獲取內容
好比說[bla_blabla name="a"]Variation A[/bla_blabla]
應該返回Variation A
我想使用正則表達式來得到它的,但有一個shortcodes.php
文件在WordPress應該已經能夠這樣做呢?你能指導我採取正確的做法嗎?
我已經目前使用此代碼
<?php
function abtest_runner($input) {
//A bit confused if you wanted equal chances of selecting one or equal changes?
//This is for equal chances.
$size = count($input);
$select = rand(0,$size-1);
$temp=array();
$selection = $input[$select];
$temp = (explode("]",$selection));
$temp = (explode("[",$temp[1]));
echo $temp[0];
}
$input[0] = '[bla_blabla name="a"]Variation A[/bla_blabla]';
$input[1] = '[bla_blabla name="b"]Variation B [/bla_blabla]';
abtest_runner($input);
?>
你正在努力達到什麼目的?可能有一個更簡單的方法! – 2015-03-03 07:08:18