Solved

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

Posted on 2013-12-27
4
504 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

707 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