如何删除http://www.来自php数组


How to remove http://www. from php array

如何从php数组、中删除http://www

这是我显示商店url的代码,我只想显示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; 
?>

尝试:

<?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>

它将从URL的开头删除http://https://,如果后面有www,则会删除。