本文整理汇总了PHP中http_build_url函数的典型用法代码示例。如果您正苦于以下问题:PHP http_build_url函数的具体用法?PHP http_build_url怎么用?PHP http_build_url使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了http_build_url函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generateCallbackUrl
/**
* Generate the callback URL to be notified when a payment is received.
* @param string $url
* @return string
*/
public function generateCallbackUrl($url)
{
if (!is_string($url)) {
throw new \InvalidArgumentException('$url is not string');
}
return http_build_url($url, array('query' => 'secret=' . $this->getSecretParameter()), HTTP_URL_STRIP_AUTH | HTTP_URL_JOIN_PATH | HTTP_URL_JOIN_QUERY | HTTP_URL_STRIP_FRAGMENT);
}
示例2: test_wwwRedirect
/**
* Test that www/no-www is handled correctly
*
* If the site is using a www URL, then no-www should redirect to www.
* If the site is using a non-www URL, then www should redirect to no-www.
*
* The redirect should be done with 301 permanent redirect status
* code. And once the user follows the redirect, he should end up on
* the correct page.
*/
public function test_wwwRedirect()
{
$components = $this->components;
$pos = strpos($components['host'], 'www.');
if ($pos === false || $pos > 0) {
$components['host'] = 'www.' . $components['host'];
} else {
$components['host'] = substr($components['host'], 4);
}
$wwwUrl = http_build_url($components);
try {
$res = $this->client->get($wwwUrl, ['allow_redirects' => false, 'timeout' => $this->timeout]);
$statusCode = $res->getStatusCode();
} catch (\Exception $e) {
$this->fail("Failed fetching URL [{$wwwUrl}] : " . $e->getMessage());
}
$this->assertEquals(301, $statusCode, "The www/no-www redirect did not return 301 status code");
try {
$res = $this->client->get($wwwUrl, ['timeout' => $this->timeout]);
$statusCode = $res->getStatusCode();
} catch (\Exception $e) {
$this->fail("Failed fetching URL [{$wwwUrl}] : " . $e->getMessage());
}
$this->assertEquals(200, $statusCode, "The www/no-www redirect did not end up in 200 status code");
}
示例3: _buildURI
private function _buildURI($append_path = null, $append_query = null)
{
$uri = $this->_uri_pieces;
if (isset($append_path)) {
if (is_array($append_path)) {
$uri['path'] = array_merge($uri['path'], $append_path);
} else {
$uri['path'][] = $append_path;
}
}
if (!empty($uri['path'])) {
$uri['path'] = '/' . implode('/', $uri['path']);
}
if (isset($append_query) && is_array($append_query)) {
foreach ($append_query as $key => $value) {
if (is_bool($value)) {
$append_query[$key] = $this->_boolString($value);
}
}
if (!empty($uri['query'])) {
$uri['query'] = array_merge($uri['query'], $append_query);
} else {
$uri['query'] = $append_query;
}
}
if (!empty($uri['query'])) {
$uri['query'] = http_build_query($uri['query']);
}
return http_build_url('http://localhost/', $uri);
}
示例4: __construct
public function __construct()
{
parent::__construct();
$this->load->model('visual_themes')->library('template');
// Determine the current visual theme.
if ($this->input->get('theme') != '' && $this->input->method() == 'get' && !$this->input->is_ajax_request()) {
$theme = (string) $this->input->get('theme');
$this->visual_themes->set_current($theme);
parse_str(parse_url(CURRENT_URL, PHP_URL_QUERY), $query);
unset($query['theme']);
redirect(http_build_url(current_url(), array('query' => http_build_query($query))));
}
$this->template->set_theme($this->visual_themes->get_current());
$default_title = config_item('default_title');
$default_description = config_item('default_description');
$default_keywords = config_item('default_keywords');
if ($default_title != '') {
$this->template->title($default_title);
}
if ($default_description != '') {
$this->template->set_metadata('description', $default_description);
}
if ($default_keywords != '') {
$this->template->set_metadata('keywords', $default_keywords);
}
$this->template->set_breadcrumb('<i class="fa fa-home"></i> ' . $this->lang->line('ui_home'), site_url());
}
示例5: create
/**
* Creates a url with the given uri, including the base url
*
* @param string $uri
* @param array $variables
* @param array $getVariables
* @param boolean $secure
*
* @return string
*/
public static function create($uri = null, $variables = [], $getVariables = [], $secure = null)
{
$url = '';
$uri = $uri ?: static::string();
// If the given uri is not a full URL
if (!preg_match("#^(http|https|ftp)://#i", $uri)) {
$url .= \Config::get('baseUrl');
if ($index_file = \Config::get('indexFile')) {
$url .= $index_file . '/';
}
}
$url .= ltrim($uri, '/');
// Add a url_suffix if defined and the url doesn't already have one
if (substr($url, -1) != '/' and (($suffix = strrchr($url, '.')) === false or strlen($suffix) > 5)) {
\Config::get('url_suffix') and $url .= \Config::get('url_suffix');
}
if (!empty($get_variables)) {
$char = strpos($url, '?') === false ? '?' : '&';
if (is_string($get_variables)) {
$url .= $char . str_replace('%3A', ':', $get_variables);
} else {
$url .= $char . str_replace('%3A', ':', http_build_query($get_variables));
}
}
array_walk($variables, function ($val, $key) use(&$url) {
$url = str_replace(':' . $key, $val, $url);
});
is_bool($secure) and $url = http_build_url($url, array('scheme' => $secure ? 'https' : 'http'));
return $url;
}
示例6: _processAnchors
protected function _processAnchors($content, $url, $depth)
{
$dom = new DOMDocument('1.0');
@$dom->loadHTML($content);
$anchors = $dom->getElementsByTagName('a');
foreach ($anchors as $element) {
$href = $element->getAttribute('href');
if (0 !== strpos($href, 'http')) {
$path = '/' . ltrim($href, '/');
if (extension_loaded('http')) {
$href = http_build_url($url, array('path' => $path));
} else {
$parts = parse_url($url);
$href = $parts['scheme'] . '://';
if (isset($parts['user']) && isset($parts['pass'])) {
$href .= $parts['user'] . ':' . $parts['pass'] . '@';
}
$href .= $parts['host'];
if (isset($parts['port'])) {
$href .= ':' . $parts['port'];
}
$href .= $path;
}
}
// Crawl only link that belongs to the start domain
$this->crawl_page($href, $depth - 1);
}
}
示例7: get
/**
* Creates a URL for requesting a custom user photo.
*/
public function get($photo, $size = null, $default_image = null, $force_default_image = null)
{
$url = $this->base_url . 'avatar/' . $photo;
$query = array();
$size = (int) $size;
if ($size <= 0) {
$size = $this->image_size;
}
if ($size > 0) {
$query['s'] = $size;
}
if (isset($default_image)) {
$default_image = (string) $default_image;
} else {
$default_image = $this->default_image;
}
if ($default_image != '') {
$query['d'] = $default_image;
}
if (isset($force_default_image)) {
$force_default_image = !empty($force_default_image);
} else {
$force_default_image = $this->force_default_image;
}
if ($force_default_image) {
$query['f'] = 'y';
}
if (!empty($query)) {
$url = http_build_url($url, array('query' => http_build_query($query)));
}
return $url;
}
示例8: cf_http_build_url
/**
* Wrapper for "http_build_url" -- will use http_build_url() if it exists, if not will do same thing.
*
* See: http://php.net/manual/en/function.http-build-query.php
*
* @param $url
* @param array $parts
* @param int $flags
* @param bool|false $new_url
*
* @return string
*/
function cf_http_build_url($url, $parts = array(), $flags = HTTP_URL_REPLACE, &$new_url = false)
{
if (function_exists('http_build_url')) {
return http_build_url($url, $parts, $flags, $new_url);
}
$keys = array('user', 'pass', 'port', 'path', 'query', 'fragment');
if ($flags & HTTP_URL_STRIP_ALL) {
$flags |= HTTP_URL_STRIP_USER;
$flags |= HTTP_URL_STRIP_PASS;
$flags |= HTTP_URL_STRIP_PORT;
$flags |= HTTP_URL_STRIP_PATH;
$flags |= HTTP_URL_STRIP_QUERY;
$flags |= HTTP_URL_STRIP_FRAGMENT;
} elseif ($flags & HTTP_URL_STRIP_AUTH) {
$flags |= HTTP_URL_STRIP_USER;
$flags |= HTTP_URL_STRIP_PASS;
}
// Parse the original URL
$parse_url = parse_url($url);
// Scheme and Host are always replaced
if (isset($parts['scheme'])) {
$parse_url['scheme'] = $parts['scheme'];
}
if (isset($parts['host'])) {
$parse_url['host'] = $parts['host'];
}
if ($flags & HTTP_URL_REPLACE) {
foreach ($keys as $key) {
if (isset($parts[$key])) {
$parse_url[$key] = $parts[$key];
}
}
} else {
if (isset($parts['path']) && $flags & HTTP_URL_JOIN_PATH) {
if (isset($parse_url['path'])) {
$parse_url['path'] = rtrim(str_replace(basename($parse_url['path']), '', $parse_url['path']), '/') . '/' . ltrim($parts['path'], '/');
} else {
$parse_url['path'] = $parts['path'];
}
}
if (isset($parts['query']) && $flags & HTTP_URL_JOIN_QUERY) {
if (isset($parse_url['query'])) {
$parse_url['query'] .= '&' . $parts['query'];
} else {
$parse_url['query'] = $parts['query'];
}
}
}
foreach ($keys as $key) {
if ($flags & (int) constant('HTTP_URL_STRIP_' . strtoupper($key))) {
unset($parse_url[$key]);
}
if (isset($parse_url[$key]) && is_array($parse_url[$key])) {
$parse_url[$key] = http_build_query($parse_url[$key]);
}
}
$new_url = $parse_url;
return (isset($parse_url['scheme']) ? $parse_url['scheme'] . '://' : '') . (isset($parse_url['user']) ? $parse_url['user'] . (isset($parse_url['pass']) ? ':' . $parse_url['pass'] : '') . '@' : '') . (isset($parse_url['host']) ? $parse_url['host'] : '') . (isset($parse_url['port']) ? ':' . $parse_url['port'] : '') . (isset($parse_url['path']) ? $parse_url['path'] : '') . (isset($parse_url['query']) ? '?' . $parse_url['query'] : '') . (isset($parse_url['fragment']) ? '#' . $parse_url['fragment'] : '');
}
示例9: joinURL
public static function joinURL($parts)
{
// imgix idiosyncracy for signing URLs when only the signature exists. Our query string must begin with '?&s='
if (substr($parts['query'], 0, 2) === "s=") {
$parts['query'] = "&" . $parts['query'];
}
return http_build_url($parts);
}
示例10: action_chat
public function action_chat()
{
$this->template->content = \View::forge('member/chat');
$config = Config::get('db.nodejs.chat', array());
$host = empty($config['host']) ? Config::get('base_url') : $config['host'];
$port = empty($config['port']) ? 0 : (int) $config['port'];
$this->template->content->chat_url = $port ? http_build_url('/', array('host' => $host, 'port' => $port)) : $host;
}
示例11: __construct
public function __construct()
{
parent::__construct();
$this->load->language('welcome')->library('curl');
$title = 'Lex Parser Test';
$this->template->append_title($title)->set_breadcrumb($title, http_build_url(site_url('playground/lex-parser'), array('query' => http_build_query(array('q_1' => 'query_param_1', 'q_2' => 'query_param_2')))));
$this->registry->set('nav', 'playground/lex');
}
示例12: validate_url
function validate_url($variable, $options = null)
{
$parsed_url = parse_url($variable);
if (empty($parsed_url) || !is_array($parsed_url) || empty($parsed_url['host'])) {
return false;
}
$parsed_url['host'] = idn_to_ascii($parsed_url['host']);
return (bool) filter_var(http_build_url($parsed_url), FILTER_VALIDATE_URL, $options);
}
示例13: authenticated_url
function authenticated_url($url)
{
// we are using HTTP authentication in this example
// if using sessions you'll want to put the session name and ID into the query string instead
$parts = array();
$parts['user'] = $_SERVER['PHP_AUTH_USER'];
$parts['pass'] = $_SERVER['PHP_AUTH_PW'];
return http_build_url($url, $parts);
}
示例14: buildURL
public function buildURL()
{
$params = [];
foreach ($this->paramsName as $key => $_name) {
$params[$_name] = $this->{$key};
}
$this->url = ($this->region ? "{$this->region}." : "") . "{$this->site}/" . ($this->mainCategory ? "/{$this->mainCategory}/" : "") . ($this->childCategory ? "/{$this->childCategory}/" : "");
return http_build_url($this->url, $params);
}
示例15: getDomainLink
/**
* Returns domain link from url.
* @param $url
* @return string
*/
protected function getDomainLink($url)
{
$parsedLink = parse_url($url);
if ($parsedLink == false) {
return "";
}
$domainLink = http_build_url($url, $parsedLink, HTTP_URL_STRIP_PATH | HTTP_URL_STRIP_QUERY | HTTP_URL_STRIP_FRAGMENT);
return $domainLink;
}