Solved

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

Posted on 2013-12-27
4
478 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
  • 3
4 Comments
 
LVL 108

Accepted Solution

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

Expert Comment

by:Ray Paseur
Comment Utility
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
Comment Utility
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 108

Expert Comment

by:Ray Paseur
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now