use yii\helpers\Url; $url = Url::to(['site/index']); echo 'Home';
use yii\helpers\Url; $url = 'https://www.example.com/?page=about'; $parsedUrl = Url::parse($url); echo $parsedUrl['scheme']; // outputs "https" echo $parsedUrl['host']; // outputs "www.example.com" echo $parsedUrl['query']; // outputs "page=about"
use yii\helpers\Url; $url = 'https://www.example.com'; if (Url::isUrl($url)) { echo 'Valid URL'; } else { echo 'Invalid URL'; }In this example, we're using the `Url::isUrl()` method to validate whether a given string is a valid URL. We then output a message indicating whether the URL is valid or not. The Yii\Helpers\Url class is part of the Yii Framework core library, which is included with the framework by default.