Solved

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

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
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 …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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 …

679 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