Page 1 of 1
Formatting the output of a variable
Posted: Tue Feb 03, 2009 5:53 am
by grunshaw
Hi guys,
I would like a little bit of help with formatting the output of a variable. This is just to further my knowledge as I am learning PHP and I just like to build things!
Its a Whois script - you can see it working here
http://grunshaw.net/thumb/. As you can see, the output of the whois at the bottom is all run together.
The whois part of the code is:
Code: Select all
<?php
$domain = $_REQUEST['url'];
$output = shell_exec("whois $domain");
echo $output;
?>
What I would like to do is format the variable $output.
If someone can help me, that would be great.
Best
James.
Re: Formatting the output of a variable
Posted: Tue Feb 03, 2009 6:00 am
by mickeyunderscore
Could you be more specific about the way in which you want to format it?
Re: Formatting the output of a variable
Posted: Tue Feb 03, 2009 6:05 am
by grunshaw
Hi,
I want to be able to find the nameservers and registrant information and may assign them to their own variables - but I generally want to format it like most Whois lookups are formatted, rather than just one huge clump.
Thanks.
James.
Re: Formatting the output of a variable
Posted: Tue Feb 03, 2009 6:43 am
by mickeyunderscore
The only way I can think of doing this at the moment is quite messy:
Code: Select all
$search = array('Domain name:', 'Registrant:', 'Registrant type:');
$replace = array('#delimiter#Domain name:', '#delimiter#Registrant:', '#delimiter#Registrant type:');
$output = str_replace($search, $replace, $output);
$chunks = explode('#delimiter#', $output);
echo $chunks[0] . '<br />';
echo $chunks[1] . '<br />';
echo $chunks[2] . '<br />';
The only thing I could think of was to insert delimiters which you can then explode on. So now $chunks[1] contains the domain name, $chunks[2] contains the registrant information.
There must be a better way than this though, if anyone knows of one?
Re: Formatting the output of a variable
Posted: Tue Feb 03, 2009 2:39 pm
by grunshaw
Hi there,
Thanks for the response - you've actually helped me out with another problem I had with searching for specific things and displaying them, so its great.
I have found a very simple solution that I will post here for everyone else to see. You will be suprised how simple this really is.
This is the code to perfomr the Whois lookup and put the data into the variable $output
Code: Select all
<?
$domain = $_REQUEST['url'];
$output = shell_exec("whois $domain");
?>
And here is the code to format it and output it in a normal Whois style so to speak.
or if your still within your <? ?> tags
I hope this is of use to someone as it has been to me and thanks again for the help.