1. Go to this page and download the library: Download belca/support library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
belca / support example snippets
use Belca\Support\AbstractConstants;
class FirstConstants extends AbstractConstants
{
const USER = 'user';
const SUPERUSER = 'superuser';
const CLIENT = 'client';
const MODERATOR = 'moderator';
const SUPERMODERATOR = 'super'.self::USER;
}
$html = "<p><b>Lorem ipsum dolor</b> sit amet, consectetur adipisicing elit, <hr> sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.<br><img src='/path/to/img.jpg'></p>";
$html = HTML::removeTags($html);
// Output: "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
$html = "<p><b class='color_red'>Lorem ipsum dolor</b> sit amet, consectetur adipisicing elit, <hr> sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.<br><img src='/path/to/img.jpg'></p>";
$allowedTags = ['b', 'hr'];
$html = HTML::removeTags($html);
// Output: "<b>Lorem ipsum dolor</b> sit amet, consectetur adipisicing elit, <hr> sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
$html = "<p><b class='color_red' style='color: green;'>Lorem ipsum dolor</b> sit amet, consectetur adipisicing elit, <hr> sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.<br><img src='/path/to/img.jpg'></p>";
$allowedTags = ['b', 'hr'];
$clearTags = true;
$allowedAttributes = ['class'];
$html = HTML::removeTags($html, $allowedTags, $clearTags, $allowedAttributes);
// Output: "<b class='color_red'>Lorem ipsum dolor</b> sit amet, consectetur adipisicing elit, <hr> sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
$html = "<p><b class='color_red' style='color: green;'>Lorem ipsum dolor</b> sit amet, consectetur adipisicing elit, <hr> sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.<br><img src='/path/to/img.jpg'></p>";
$allowedTags = ['b', 'hr'];
$html = HTML::removeTags($html, $allowedTags, false);
// Output: "<b class='color_red' style='color: green;'>Lorem ipsum dolor</b> sit amet, consectetur adipisicing elit, <hr> sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
$html = "<p><b>Lorem ipsum dolor</b> sit amet, consectetur adipisicing elit, <hr> sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.<br><img src='/path/to/img.jpg'></p>";
$html = HTML::removeTagContent($html, $tags = ['p', 'b', 'br', 'img']); // Output: ''
$html = "<p><b>Lorem ipsum dolor</b> sit amet, consectetur adipisicing elit, <hr> sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.<br><img src='/path/to/img.jpg'></p>";
$html = HTML::removeTagContent($html, $tags = ['b', 'br', 'img']);
// Output: "<p> sit amet, consectetur adipisicing elit, <hr> sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>";
$html = "<p><b>Lorem ipsum dolor</b> sit amet, consectetur adipisicing elit, <hr> sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.<br><img src='/path/to/img.jpg'></p>";
$html = HTML::removeSingleTags($html, $allowed = ['hr']);
// Output: "<p><b>Lorem ipsum dolor</b> sit amet, consectetur adipisicing elit, <hr> sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>";
$source = "AABC aabbcc A A aaaaAAAA A A A B B";
$result = Str::removeDuplicateSymbols($source, 'A ', 1); // 1+1 = 2 и более вхождений в подстроку
// Output: "ABC aabbcc A A aaaaA A A A B B"
$source = "AABC aabbcc A A aaaaAAAA A A A B B";
$result = Str::removeDuplicateSymbols($source, 'A', 1, true); // 1+1 = 2 вхождения
// Output: "ABC aabbcc A A aaaaAA A A A B B"
$source = "ABC aabbcc aaaaAAAA A A A B B B A A A";
$result = Str::reduceDuplicateSymbols($source, 'A', 2);
// Output: "ABC aabbcc aaaaAA A A A B B B A A A"
$source = "ABC aabbcc aaaaAAAA A A A B B B A A A";
$result = Str::reduceDuplicateSymbols($source, 'A ', 2);
// Output: "ABC aabbcc aaaaAAAA A A B B B A A A"
$string = "Lorem ipsum dolor sit amet... dolore magna aliqua.";
# Example 1: Поиск значения без дополнительных параметров
$result = Str::findPositionFromEnd($string, "dolor"); // Output: 30
# Example 2: Поиск значения без отступа от конца строки, а возвращаемая позиция должна отсчитываться с конца строки с позиции '-1'.
$result = Str::findPositionFromEnd($string, "dolor", 0, true); // Output: -20
# Example 3: Поиск значения с отступом с конца в 20 символов.
$result = Str::findPositionFromEnd($string, "dolor", 20); // Output: 12
# Example 4: Поиск значения с отступом с конца в 20 символов и возврат значения с отчетом с конца строки.
$result = Str::findPositionFromEnd($string, "dolor", 20, true); // Output: -38
# Example 5: Поиск одного символа
$result = Str::findPositionFromEnd($string, "."); // Output: 49
# Example 6: Поиск одного символа с конца строки и возврат значения с отчетом с конца строки.
$result = Str::findPositionFromEnd($string, ".", 0, true); // Output: -1
# Example 7: Поиск несуществующего символа
$result = Str::findPositionFromEnd($string, "!"); // Output: null
$string = "Lorem ipsum dolor sit amet... dolore magna aliqua.";
$result = Str::findPositionFromEnd($string, "dolor", 0, true);
$result = ($result + 1) * (-1); // 19
// or
$result = abs($result + 1); // 19