Replaces preg_replace by mb_ereg_replace

* No more use of separators.
* \$1 becomes \\1
This commit is contained in:
Christophe HENRY 2021-03-04 21:22:41 +01:00
parent 011f38c36f
commit e723f268fc
2 changed files with 8 additions and 4 deletions

View File

@ -18,4 +18,8 @@ With Nginx, you can use:
rewrite ^(.+\.gmi)$ /htmgem.php?url=$1 last;
```
## Install
php-mbstring is required
So the page is available at [http://thesite/htmgem.php/directory/page.gmi].

View File

@ -47,14 +47,13 @@ EOL);
* @param &$text where to replace.
*/
function markupPreg($instruction, $markup, &$text) {
#return preg_replace("#{$instruction}((?!{$instruction}.)+)(?:{$instruction})?#", "<{$markup}>$1</{$markup}>", $text);
$output = $text;
# Replaces couples "__word__" into "<i>word</i>".
$output = preg_replace("#${instruction}(.+?)${instruction}#", "<{$markup}>$1</{$markup}>", $output);
$output = mb_ereg_replace("${instruction}(.+?)${instruction}", "<{$markup}>\\1</{$markup}>", $output);
# Replaces a remaining __ into "<i>…</i>" to the end of the line.
$output = preg_replace("#${instruction}(.+)?#", "<{$markup}>$1</{$markup}>", $output);
$output = mb_ereg_replace("${instruction}(.+)?", "<{$markup}>\\1</{$markup}>", $output);
$text = $output;
}
@ -77,7 +76,8 @@ function addTextAttributes(&$line) {
*/
function htmlEscape(&$text) {
$text = htmlspecialchars($text, ENT_HTML5, "UTF-8", false);
$text = preg_replace("#\ ([?!;])#", "&#8239;\$1", $text); # Espace fine insécable
$text = mb_ereg_replace("\ ([?!:;»€$])", "&#8239;\\1", $text); # Espace fine insécable
$text = mb_ereg_replace("([«])\ ", "\\1&#8239;", $text); # Espace fine insécable
}
$mode = null;