0

ストア ページにストアの URL を表示するクーポン サイトがあります。私が欲しいのは、最初に http:// バリエーションを表示せずに、各ストアの最後にある .com のみです

ストアの URL を表示するコードを次に示します。 http://www.domain.comの代わりに domain.com を表示したいだけで、 http://domain.comとして表示される場合もあります。

<p class="store-url"><a href="<?php echo $url_out; ?>" target="_blank"><?php echo $stores_url; ?>

この機能によりこのように表示されます

<div class="store"> 
<?php // grab the store meta data 
$term = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy'));
$stores_url = esc_url(get_metadata(APP_TAX_STORE, $term->term_id, 'clpr_store_url',       true));
$dest_url = esc_url(get_metadata(APP_TAX_STORE, $term->term_id, 'clpr_store_aff_url',     true));

// if there's a store aff link, then cloak it. else use store url
if ($dest_url)
$url_out = esc_url(home_url(CLPR_STORE_REDIRECT_BASE_URL . $term->slug));
else
$url_out = $stores_url; 

?>

できること.......

4

3 に答える 3

0

これは、preg_replaceが作成された目的です。

<?php
$http_url = 'http://www.somestore.com/some/path/to/a/page.aspx';
$domain = preg_replace('#^https?://(?:www\.)?(.*?)(?:/.*)$#', '$1', $http_url);
print $domain;
?>
このコードは印刷されます

somestore.com

于 2012-08-02T19:03:50.293 に答える
0

手早く汚い - 可能な機能をデモンストレーションするには...

<?php
function cleanInputString($inputString) {
    // lower chars
    $inputString = strtolower($inputString);

    // remove whitespaces
    $inputString = str_replace(' ', '', $inputString);

    // check for .com at the end or add otherwise
    if(substr($inputString, -4) == '.com') {
        return $inputString;
    } else {
        return $inputString .'.com';
    }
}

// example
$inputStrings = array(
 'xyzexamp.com',
 'xyzexamp',
 'xyz examp'
);

foreach($inputStrings as $string) {
    echo('input: '. $string .'; output: '. cleanInputString($string) .'<br />');
}
?>

出力:

input: xyzexamp.com; output: xyzexamp.com
input: xyzexamp; output: xyzexamp.com
input: xyz examp; output: xyzexamp.com
于 2012-08-01T07:24:42.327 に答える
0

「正しい方法」は、おそらく PHP の URL 処理を使用することです。

  1. http://php.net/manual/en/function.parse-url.phpを使用して URL を分割します
  2. unset を使用して、結果の配列のスキーム要素を削除します
  3. http://www.php.net/manual/en/function.http-build-url.phpを使用して再度ビルドします
于 2012-08-02T18:46:24.313 に答える