2012-08-01 127 views
0

我有一个优惠券网站,显示商店页面上的商店网址。我想要的只是在每个商店末尾没有显示http://开头处的http://变体如何去除http:// www。从PHP功能只留下.com

这里是我的代码,显示商店网址,我只想要显示domain.com而不是http://www.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; 

?> 

可以做些什么................

回答

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 />'); 
} 
?> 

OUTPUT:

input: xyzexamp.com; output: xyzexamp.com 
input: xyzexamp; output: xyzexamp.com 
input: xyz examp; output: xyzexamp.com 
+0

没有工作.... – 2012-08-02 18:32:47

+0

我重新提交的问题与更多细节 – 2012-08-02 18:43:27

0

的 “正确的方式” 可能是使用PHP URL处理:

  1. 使用破解URL http://php.net/manual/en/function.parse-url.php
  2. 删除生成的arr的scheme元素唉通过取消设置
  3. 构建它再次使用http://www.php.net/manual/en/function.http-build-url.php
+0

'parse_url'是一个好主意,但是如果它存在的话,你仍然需要去掉领先的'www.'',并且它看起来不像作者想要的任何东西ng但解析后的url中的** PHP_URL_HOST **。 – JL344 2012-08-02 19:29:29