| 1 |
<?php |
| 2 |
namespace Elementor\Core\Utils; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; // Exit if accessed directly |
| 6 |
} |
| 7 |
|
| 8 |
class Str { |
| 9 |
|
| 10 |
/** |
| 11 |
* Convert a non-latin URL to an IDN one. |
| 12 |
* Note: Max length is 64 chars. |
| 13 |
* |
| 14 |
* @param string $url - A URL to encode. |
| 15 |
* |
| 16 |
* @return string - IDN encoded URL ( e.g. `http://é.com` will be encoded to `http://xn--9ca.com` ). |
| 17 |
*/ |
| 18 |
public static function encode_idn_url( $url ) { |
| 19 |
return preg_replace_callback( '/(https?:\/\/)(.+)/', function ( $matches ) { |
| 20 |
return $matches[1] . \Requests_IDNAEncoder::encode( $matches[2] ); |
| 21 |
}, $url ); |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* Checks if a string ends with a given substring |
| 26 |
* |
| 27 |
* @param $haystack |
| 28 |
* @param $needle |
| 29 |
* @return bool |
| 30 |
*/ |
| 31 |
public static function ends_with( $haystack, $needle ) { |
| 32 |
return substr( $haystack, -strlen( $needle ) ) === $needle; |
| 33 |
} |
| 34 |
} |
| 35 |
|