0

我正在使用这个 php 代码

    <title>Web Design <?php
    echo ucwords(array_shift(explode(".",$_SERVER['HTTP_HOST'])));
    ?>, Website Design</title>

获取效果很好的子域(subdomain.domain.co.uk)但是 - 我希望它忽略连字符并将连字符的子域的单词大写,即 sub-domain.domain.co.uk => Sub Domain

我必须将代码更改为什么?

4

2 回答 2

0

str_replace('-', ' ', $subdomain)在调用之前使用空格ucwords替换。-例如:

<?php
$subdomain = array_shift(explode(".",$_SERVER['HTTP_HOST']));
echo ucwords(str_replace('-', ' ', $subdomain));
?>
于 2013-08-24T10:26:44.993 回答
0

试过了str_replace吗?

<?php
  $domain = $_SERVER["HTTP_HOST"];
  $domain = explode( ".", $domain ); // split domain by comma
  $domain = array_shift( $domain ); // shift an element off the begginning of array
  $domain = str_replace( "-", " ", $domain ); // replace all occureance of '-' to space
  $domain = ucwords( $domain ); // uppercase the first character of words

  echo $domain;
?>
于 2013-08-24T10:27:13.330 回答