| |
|
27.04.2012, 12:36
|
#1
|
|
(..)
|
php!?
, , :
PHP ,
<a href="http://google.com/1">{search|images|maps|Calendar}</a>
<a href="http://google.com/2">{1|2|3|4}</a>
<a href="http://google.com/3">{A|B|C|D}</a>
{} ?
. - <a href="http://google.com/1">search</a> <a href="http://google.com/2">4</a> <a href="http://google.com/3">B</a>
- , 1 20.
|
|
|
27.04.2012, 12:56
|
#2
|
|
Senior Member
|
PHP :
$string = '<a href="http://google.com/1">{search|images|maps|Calendar}</a>'; echo spin_text($string); function spin_text($string) { if (preg_match('/\{([^\}]*)\}/i', $string, $random_words)) { $random_words_array = explode("|", $random_words[1]); if (is_array($random_words_array)) { shuffle($random_words_array); $string = preg_replace('/\{[^\}]*\}/i', $random_words_array[0], $string); } } return $string; }
|
|
|
27.04.2012, 13:00
|
#3
|
|
(..)
|
, 1 , .
.
seroja; 27.04.2012 13:15.
|
|
|
27.04.2012, 13:12
|
#4
|
|
Senior Member
|
seroja, , 
|
|
|
27.04.2012, 13:57
|
#5
|
|
|
PHP :
$content = '<a href="http://google.com/1">{search|images|maps|Calendar}</a> <a href="http://google.com/2">{1|2|3|4}</a> <a href="http://google.com/3">{A|B|C|D}</a>';
function spinaround($content)
{
preg_match_all('/{(.*)}/sU',$content,$matches);
foreach ($matches[0] as $k=>$v)
{
$string = $matches[1][$k];
if ( preg_match_all('/\[(.*)\]/sU',$string,$stringmatches) )
{
foreach ($stringmatches[0] as $l=>$w)
{
$new = explode('|',$stringmatches[1][$l]);
$new = $new[array_rand($new)];
$string = str_replace($w,$new,$string);
}
}
$new = explode('|',$string);
$new = $new[array_rand($new)];
$content = str_replace($v,$new,$content);
}
return $content;
}
echo spinaround($content);
|
|
|
04.05.2012, 17:41
|
#6
|
|
|
PHP :
$t = "{||} {|} {|}!";
echo $t = preg_replace_callback("/\{([^{}]*?)\}/ism", "callback", $t);
function callback($matches) {
$v = preg_split("/(?<!\|)\|(?!\|)/", $matches[1]);
return $v[array_rand($v)];
}
|
|
|
30.05.2012, 12:57
|
#7
|
|
|
:
vilnus
PHP :
$t = "{||} {|} {|}!";
echo $t = preg_replace_callback("/\{([^{}]*?)\}/ism", "callback", $t);
function callback($matches) {
$v = preg_split("/(?<!\|)\|(?!\|)/", $matches[1]);
return $v[array_rand($v)];
}
|
!
|
|
|
|
|
|