We Recommend

Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems
Wicked Cool PHP contains a wide variety of scripts to process credit cards, check the validity of email addresses, template HTML, and serve dynamic images and text.


Posted By

fris on 03/02/08


Tagged

regex css wordpress domain


Versions (?)


splitting a domain in half


Published in: PHP 


My wordpress theme uses the site name in the header (top) and i needed to split it in half , in order to style it correctly in css


  1. <?
  2. if( isset($_SERVER['HTTP_HOST']) && preg_match("/([^\.]+)\.(com|net|org|info|mobi|biz|ca|us|tv|cc|eu|be|de|jp|nl|ws|fi)/", $_SERVER['HTTP_HOST'], $matches) ){
  3. $len = intval(strlen($matches[1])/2);
  4. $first_half = substr($matches[1],0,$len);
  5. $second_half = substr($matches[1],$len);
  6. echo "<h1><a href=\"<?php bloginfo('url'); ?>\">$first_half<span class=\"subdomain\">$second_half</span></a></h1>";
  7. }
  8. ?>

Report this snippet 

You need to login to post a comment.