Solved

PHP str_replace(all Text Before A dot & all Text After that dot

Posted on 2013-12-27
4
501 Views
Last Modified: 2013-12-27
Hi Guys,
Using PHP str_replace I'm trying to break down a domain name (ANYdomain1.ANYdomain2) into its parts,
so that I can get this result:
$domainPart1=ANYdomain1';
and
$domainPart2=ANYdomain2';

I also want to delete the "." (dot) between ANYdomain1.ANYdomain2.
I can't find my solution on the web, but I think this is an easy one for the experts.
Thanks in advance,
Sas
0
Comment
Question by:sasnaktiv
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 39742286
http://www.php.net/manual/en/function.explode.php will do it.  Use the dot as the string separator.
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39742288
That said, you might want to think carefully about your test data.  For example, consider these two URLs: www.twitter.com and twitter.com.  What is the exact output you would want from each of those?
0
 
LVL 1

Author Closing Comment

by:sasnaktiv
ID: 39742379
Thanks Ray,
I can always address the "www." by starting with this:

$http_host = str_replace('http://www.', '' , $_SERVER['HTTP_HOST']);
$http_host=str_replace('www.', '',$http_host);

Then following with the EXPLODE you suggested.

Thanks again,
Sas
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39742529
Thanks for the points - just be careful about the structure you expect to get from URLs.  There are things like domain.com.uk that may produce "interesting" results.

Best regards, ~Ray
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question