From 501a64e0c7b8709a9559a1d22e60e1f26ade0b33 Mon Sep 17 00:00:00 2001 From: kplaczek Date: Thu, 19 Apr 2018 22:59:47 +0200 Subject: [PATCH] Removes before printing lines with ! or # as a leading characer even after some space characters in front. --- app/Paper/HtmlToPos.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/Paper/HtmlToPos.php b/app/Paper/HtmlToPos.php index 0f033ca..aa2ed4e 100644 --- a/app/Paper/HtmlToPos.php +++ b/app/Paper/HtmlToPos.php @@ -15,6 +15,12 @@ class HtmlToPos public function convert($html = '') { $posText = $this->handleNewLine($html); + + /** + * usuwa linijki które na początku mają ! albo # + */ + $posText = preg_replace('/^\s*[!#].*?$[\r\n]/m', '', $posText); + /** * przeszukiwanie tekstu pod katem zawartości [ liczba, liczba2 ] i zamienianiu tego na randomową liczbę z przedziału * liczba - liczba2 @@ -24,8 +30,10 @@ class HtmlToPos 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])); + $posText = substr_replace($posText, mb_rand($match[1], $match[2]), $pos, strlen($match[0])); } + + die(); return $posText; }