This repository has been archived on 2019-03-01. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
paper-pi/app/Paper/HtmlToPos.php

40 lines
1019 B
PHP

<?php
namespace App\Paper;
class HtmlToPos
{
private function handleNewLine($text)
{
return str_replace(['<br>', '<br/>', '<br />'], "\n", $text);
}
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
* 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, mb_rand($match[1], $match[2]), $pos, strlen($match[0]));
}
die();
return $posText;
}
}