PHP code example of ramsey / str-begins-ends

1. Go to this page and download the library: Download ramsey/str-begins-ends 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/ */

    

ramsey / str-begins-ends example snippets

 php
$url = 'http://example.com';

if (str_starts_with($url, 'http://')) {
    $url = str_replace('http://', 'https://', $url);
}
 php
$file = '/path/to/something.log';

if (str_ends_with($file, '.log')) {
    $contents = file_get_contents($file);
}
 php
$url = 'HTTPS://example.com';

if (str_begins_with_ci($url, 'https://')) {
    $url = substr($url, 8);
}
 php
$file = '/path/to/something.TXT';

if (str_ends_with_ci($file, '.txt')) {
    $contents = file_get_contents($file);
}
 php
$sanskrit = 'काचं शक्नोम्यत्तुम् । नोपहिनस्ति माम् ॥';

if (mb_str_ends_with($sanskrit, 'माम् ॥')) {
    $translation = 'I can eat glass';
}
 php
$poem = 'Τὴ γλῶσσα μοῦ ἔδωσαν ἑλληνικὴ';

if (mb_str_begins_with_ci($poem, 'ΤῊ')) {
    $poet = 'Οδυσσέας Ελύτης';
}
 php
$poem = 'Τὴ γλῶσσα μοῦ ἔδωσαν ἑλληνικὴ';

if (mb_str_ends_with_ci($poem, 'ἙΛΛΗΝΙΚῊ')) {
    $poet = 'Οδυσσέας Ελύτης';
}