2012-08-02 83 views
-2

如何删除http:// www。从PHP数组,如何删除http:// www。 from php array

这里是我的代码显示一个商店网址,我只是想显示的,而不是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; 

?> 
+0

所以总结一下,你想从字符串'$ url_out'中删除一个子字符串? – Matt 2012-08-02 18:30:10

+1

对于那些正在投票的人,请向OP解释你为什么这样做,以便他可以改善他的问题,如果需要的话。 – Matt 2012-08-02 18:32:07

回答

0

尝试:

<?php $stores_url = preg_replace('/^https?:\/\/(?:www\.)?/i', '', $stores_url); ?> 
<p class="store-url"><a href="<?php echo $url_out; ?>" target="_blank"> 
    <?php echo $stores_url ?> 
</p> 

它会从网址开头删除http://https://以及如下所示的www

+0

哇,谢谢你的工作......................谢谢 – 2012-08-03 21:43:08

+0

不客气,如果这是一个适当的解决方案,你可以继续接受通过点击答案左边的绿色复选标记来回答。 – drew010 2012-08-03 21:43:53

+0

随时回答我的其他问题 – 2012-08-03 22:10:47