| @@ 441-475 (lines=35) @@ | ||
| 438 | * |
|
| 439 | * @return string |
|
| 440 | */ |
|
| 441 | public static function replaceToPreserveHtmlEntities(string $html): string |
|
| 442 | { |
|
| 443 | // init |
|
| 444 | $linksNew = []; |
|
| 445 | $linksOld = []; |
|
| 446 | ||
| 447 | if (\strpos($html, 'http') !== false) { |
|
| 448 | ||
| 449 | // regEx for e.g.: [https://www.domain.de/foo.php?foobar=1&email=lars%40moelleken.org&guid=test1233312&{{foo}}#foo] |
|
| 450 | $regExUrl = '/(\[?\bhttps?:\/\/[^\s<>]+(?:\([\w]+\)|[^[:punct:]\s]|\/|\}|\]))/i'; |
|
| 451 | \preg_match_all($regExUrl, $html, $linksOld); |
|
| 452 | ||
| 453 | if (!empty($linksOld[1])) { |
|
| 454 | $linksOld = $linksOld[1]; |
|
| 455 | foreach ((array) $linksOld as $linkKey => $linkOld) { |
|
| 456 | $linksNew[$linkKey] = \str_replace( |
|
| 457 | self::$domLinkReplaceHelper['orig'], |
|
| 458 | self::$domLinkReplaceHelper['tmp'], |
|
| 459 | $linkOld |
|
| 460 | ); |
|
| 461 | } |
|
| 462 | } |
|
| 463 | } |
|
| 464 | ||
| 465 | $linksNewCount = \count($linksNew); |
|
| 466 | if ($linksNewCount > 0 && \count($linksOld) === $linksNewCount) { |
|
| 467 | $search = \array_merge($linksOld, self::$domReplaceHelper['orig']); |
|
| 468 | $replace = \array_merge($linksNew, self::$domReplaceHelper['tmp']); |
|
| 469 | } else { |
|
| 470 | $search = self::$domReplaceHelper['orig']; |
|
| 471 | $replace = self::$domReplaceHelper['tmp']; |
|
| 472 | } |
|
| 473 | ||
| 474 | return \str_replace($search, $replace, $html); |
|
| 475 | } |
|
| 476 | } |
|
| 477 | ||
| @@ 747-781 (lines=35) @@ | ||
| 744 | * |
|
| 745 | * @return string |
|
| 746 | */ |
|
| 747 | public static function replaceToPreserveHtmlEntities(string $html): string |
|
| 748 | { |
|
| 749 | // init |
|
| 750 | $linksNew = []; |
|
| 751 | $linksOld = []; |
|
| 752 | ||
| 753 | if (\strpos($html, 'http') !== false) { |
|
| 754 | ||
| 755 | // regEx for e.g.: [https://www.domain.de/foo.php?foobar=1&email=lars%40moelleken.org&guid=test1233312&{{foo}}#foo] |
|
| 756 | $regExUrl = '/(\[?\bhttps?:\/\/[^\s<>]+(?:\([\w]+\)|[^[:punct:]\s]|\/|\}|\]))/i'; |
|
| 757 | \preg_match_all($regExUrl, $html, $linksOld); |
|
| 758 | ||
| 759 | if (!empty($linksOld[1])) { |
|
| 760 | $linksOld = $linksOld[1]; |
|
| 761 | foreach ((array) $linksOld as $linkKey => $linkOld) { |
|
| 762 | $linksNew[$linkKey] = \str_replace( |
|
| 763 | self::$domLinkReplaceHelper['orig'], |
|
| 764 | self::$domLinkReplaceHelper['tmp'], |
|
| 765 | $linkOld |
|
| 766 | ); |
|
| 767 | } |
|
| 768 | } |
|
| 769 | } |
|
| 770 | ||
| 771 | $linksNewCount = \count($linksNew); |
|
| 772 | if ($linksNewCount > 0 && \count($linksOld) === $linksNewCount) { |
|
| 773 | $search = \array_merge($linksOld, self::$domReplaceHelper['orig']); |
|
| 774 | $replace = \array_merge($linksNew, self::$domReplaceHelper['tmp']); |
|
| 775 | } else { |
|
| 776 | $search = self::$domReplaceHelper['orig']; |
|
| 777 | $replace = self::$domReplaceHelper['tmp']; |
|
| 778 | } |
|
| 779 | ||
| 780 | return \str_replace($search, $replace, $html); |
|
| 781 | } |
|
| 782 | ||
| 783 | /** |
|
| 784 | * Get the HTML as XML or plain XML if needed. |
|