From 680e52e2b49c569cf7cab9170f9a91c517895953 Mon Sep 17 00:00:00 2001 From: kplaczek Date: Tue, 17 Apr 2018 18:00:06 +0200 Subject: [PATCH] Added a way to check if there is a [ number, number2 ] in a text and then replace that with a random number from that range. --- app/Paper/HtmlToPos.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/Paper/HtmlToPos.php b/app/Paper/HtmlToPos.php index 57d410d..0f033ca 100644 --- a/app/Paper/HtmlToPos.php +++ b/app/Paper/HtmlToPos.php @@ -15,6 +15,17 @@ class HtmlToPos public function convert($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; }