使用以下代码从输出中删除 WWW


Remove WWW from output using the code below

<?php wpfp_link() ?>
<small>
<?php 
    $url = esc_url( get_post_meta( $post->ID, '_source_link', true ) );
    $parse = parse_url($url);
    print $parse['host'];
?>

上面的代码给出了输出:

www.example.com

我想要的是删除WWW部分,以便输出

emaple.com
If(substr($parse,0,3)=="www")  $parse = substr($parse,3)
//or
preg_match("/'.?(.*'..*)/", $input_line, $output_array);

http://www.phpliveregex.com/p/fD4

编辑:哎呀忘记了?

可能你必须使用这样的东西,

 <?php 
  $url = esc_url( get_post_meta( $post->ID, '_source_link', true ) );
  $parse = parse_url($url);
  $email  = 'name@example.com';
  $domain = strstr($parse, '.');
  echo $domain; // prints example.com
 ?> 

此函数检查 . 并删除其他字符串,因此如果您有类似 、 http://www.example.com 的 url,这将给出 put example.com

只需使用str_replace函数。

$parse['host'] = 'www.example.com';
$only_domain = str_replace("www.", "", $parse['host']); //example.com