Losowanie liczb po wpisaniu do wydrukowania [cyfra, cyfra2 ] #12
@@ -15,6 +15,17 @@ class HtmlToPos
|
|||||||
public function convert($html = '')
|
public function convert($html = '')
|
||||||
{
|
{
|
||||||
$posText = $this->handleNewLine($html);
|
$posText = $this->handleNewLine($html);
|
||||||
|
/**
|
||||||
|
* przeszukiwanie tekstu pod katem zawartości [ liczba, liczba2 ] i zamienianiu tego na randomową liczbę z przedziału
|
||||||
|
* liczba - liczba2
|
||||||
|
* obojętnie czy ujemną czy nie
|
||||||
|
*/
|
||||||
|
$re = '/\[\s*(-?\d+)\s*\,\s*(-?\d+)\s*\]/';
|
||||||
|
preg_match_all($re, $html, $matches, PREG_SET_ORDER, 0);
|
||||||
|
foreach ($matches as $match) {
|
||||||
|
$pos = strpos($posText, $match[0]);
|
||||||
|
$posText = substr_replace($posText, rand($match[1], $match[2]), $pos, strlen($match[0]));
|
||||||
|
}
|
||||||
return $posText;
|
return $posText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user