Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Removing characters in php

Posted on 2007-03-26
4
Medium Priority
?
236 Views
Last Modified: 2007-03-26
I'm trying to echo out a list of domain names in php.  I need to print the sld and tld part separately (example sld=mydomain tld=com), how do I strip the text before and after the period using php?

BTW: Some domains have a 2 letter country code, so I can't just strip the last 4 characters.
0
Comment
Question by:thunder99
[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
  • 2
4 Comments
 
LVL 29

Accepted Solution

by:
TeRReF earned 1000 total points
ID: 18792001
$s = 'domain.com';
list($sld, $tld) = explode('.', $s);
echo $sld.'<br>'.$tld;
0
 
LVL 27

Assisted Solution

by:Cornelia Yoder
Cornelia Yoder earned 1000 total points
ID: 18792002
$array = explode(".",$url);
$firstpart = $array[0];
$lastpart = $array[1];

This only works for a two-part name like the example you gave.

If you need to break out abc.xyz.com into more parts, you do it the same way, but $array will have each part between the periods as a separate element in the array.  You can reassemble the parts however you need.
0
 

Author Comment

by:thunder99
ID: 18792116
That was quick.

Both answers work (I went with yodercm's though) and both have the same timestamp, so I'm going to accept multiple solutions.

Thanks guys (or gals).
0
 
LVL 27

Expert Comment

by:Cornelia Yoder
ID: 18792361
Good job, thunder99.  It's right to share the points for simultaneous correct answers.  Thanks!
0

Featured Post

Industry Leaders: 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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
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 …

688 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