panduanvip / helpers
Text or string manipulation
Installs: 1 863
Dependents: 4
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
This package is auto-updated.
Last update: 2024-12-06 07:40:48 UTC
README
A collection of PHP functions that I often use
Installation:
composer require panduanvip/helpers
Usage:
<?php include 'vendor/autoload.php'; use PanduanVIP\Helpers\Please;
Get web content
echo Please::getWebContent('https://google.com');
Result:
return html page from google.com
Get multiple web contents
echo Please::getWebContents(['https://google.com', 'https://yahoo.com']);
Result:
return html pages from google.com dan yahoo.com
Create random string
echo Please::createRandomString();
Result:
7y2cNs
Pick one item from the array randomly
$array = ['Pen', 'Book', 'Laptop', 'Bus', 'Plane', '']; $result = Please::pickOneRandom($array);
Result:
Book
Trim all spaces near separators
$string = "Gunadarma , Jayabaya, Pancasila,,"; $result = Please::trimAllSpaces($string, ',');
Result:
Gunadarma,Jayabaya,Pancasila
Make a sentence from a spintax
$string = "{green|blue|yellow} bird is sitting {there|over there|on the ground}."; $result = Please::createSpintax($string);
Result:
blue bird is sitting on the ground.
Converts string to array based on newlines
$string = <<<test Example of string spanning multiple lines using heredoc syntax. test; $result = Please::explodeNewLine($string);
Result:
['Example of string', 'spanning multiple lines', 'using heredoc syntax.']
Create excerpt from a paragraph
$string = "PHP is a general-purpose scripting language especially suited to web development. It was stringly created by Danish-Canadian programmer Rasmus Lerdorf in 1994. The PHP reference implementation is now produced by The PHP Group."; $result = Please::createExcerpt($string, 50);
Result:
PHP is a general-purpose scripting language...
Replace double with single space
$string = "Lorem ipsum dolor sit amet, consectetur adipiscing elit"; $result = Please::removeDoubleSpace($string);
Result:
Lorem ipsum dolor sit amet, consectetur adipiscing elit
Get a string between two strings
$string = "This is my dog!"; $result = Please::getStringBetween($string, "my", "!");
Result:
dog
Sanitize string for creating url slug
$string = "красивые сакуры"; $result = Please::createSlug($string);
Result
красивые-сакуры