FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » My first PHP Script...
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
My first PHP Script... [message #175797] Wed, 26 October 2011 23:26 Go to next message
SpreadTooThin is currently offline  SpreadTooThin
Messages: 3
Registered: October 2011
Karma: 0
Junior Member
Hi, I'm a seasoned programmer that needs to do this one program and
then I'll probably never program in PHP for another 5 years....

I have a perl script that was created by another programmer, who is
long gone...
I need to take the output of that script and then 'massage' it so that
the data can be formated and displayed to my liking..

The script is

http://myserver/cgi-bin/path/deptlist.pl?dept=HR

This script gives me a phone list of all the people in HR except the
color coding is terrible.
So pardon my ignorance here but this is where I was told to start...

<?php
include_once "deptlist.pl";
?>

Not much to go on, but is there a way to get the output of the script
into a string variable and then parse the string and produce the
output to my liking?

Should i be attempting this in PHP or should I perhaps try java
script?

Get me started and I'll figure out the rest....
Thanks.
Re: My first PHP Script... [message #175798 is a reply to message #175797] Thu, 27 October 2011 01:00 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On Wed, 26 Oct 2011 16:26:41 -0700, SpreadTooThin wrote:

> Hi, I'm a seasoned programmer that needs to do this one program and then
> I'll probably never program in PHP for another 5 years....
>
> I have a perl script that was created by another programmer, who is long
> gone...
> I need to take the output of that script and then 'massage' it so that
> the data can be formated and displayed to my liking..
>
> The script is
>
> http://myserver/cgi-bin/path/deptlist.pl?dept=HR
>
> This script gives me a phone list of all the people in HR except the
> color coding is terrible.
> So pardon my ignorance here but this is where I was told to start...
>
> <?php
> include_once "deptlist.pl";
> ?>

Doesn't sound right

What you may want to do, depending on whether you want a string, an
array, or a tree of nodes, is:

<?php
$str = file_get_contents("http://myserver/cgi-bin/path/deptlist.pl?
dept=HR");

// $str contains the whole output of the perl script including any
linebreaks
?>

<?php
$ary = file("http://myserver/cgi-bin/path/deptlist.pl?
dept=HR",FILE_IGNORE_NEW_LINES);

// $ary contains the whole output of the perl script as an array of lines
(without terminating linebreaks)
?>

<?php
$doc = new DOMDocument();
$doc->loadHTMLFile("http://myserver/cgi-bin/path/deptlist.pl?dept=HR");

// $doc is the root of a tree of nodes that represents the html document
generated by the perl script

$body = $doc->getElementsByTagName('body')->item(0);

// $body is the root of a tree of nodes that represents the html document
<body>contents</body> element generated by the perl script

// If the body contains tables, name in cell 0, room number in cell 1,
ext in cell 2, and you want name and ext:

$rows = $body->getElementsByTagName('tr');
for ($iR = 0; $iR < $rows->length; $iR++)
{
$cells = $rows->item($iR)->getElementsByTagName('td');
$name = $cells->item(0)->textContent;
$ext = $cells->item(2)->textContent;
file_put_contents ("new_file.txt","{$name} {$ext}\n",FILE_APPEND);
}

// if the body contains lists and you just want the content of the "li"
elements:
$items = $body->getElementsByTagName('li');
for ($iR = 0; $iR < $rows->length; $iR++)
{
$data = $items->item($iR)->textContent;
file_put_contents ("new_file.txt","{$data}\n",FILE_APPEND);
}

// etc
?>

Opening a url with the file open commands depends on the relevant ini
value being set to enable this, however I believe it is the default
setting.

If the perl script generates reasonably well structured html, it may be
easier to manipulate and output it using the domdocument methods.

Rgds

Denis McMahon
Re: My first PHP Script... [message #175801 is a reply to message #175798] Thu, 27 October 2011 03:22 Go to previous messageGo to next message
SpreadTooThin is currently offline  SpreadTooThin
Messages: 3
Registered: October 2011
Karma: 0
Junior Member
> Rgds
>
> Denis McMahon

Thank you very much.
You understood my posting perfectly.
Re: My first PHP Script... [message #175802 is a reply to message #175798] Thu, 27 October 2011 03:31 Go to previous messageGo to next message
SpreadTooThin is currently offline  SpreadTooThin
Messages: 3
Registered: October 2011
Karma: 0
Junior Member
> If the perl script generates reasonably well structured html, it may be
> easier to manipulate and output it using the domdocument methods.
>
I wish I could just get the source of the pearl script and modify
that...
Re: My first PHP Script... [message #175803 is a reply to message #175802] Thu, 27 October 2011 04:22 Go to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 10/26/2011 11:31 PM, SpreadTooThin wrote:
>
>> If the perl script generates reasonably well structured html, it may be
>> easier to manipulate and output it using the domdocument methods.
>>
> I wish I could just get the source of the pearl script and modify
> that...

Why can't you? It's a script, not a compiled language. And if you're
doing it for the customer who owns the script, they have it on their server.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: populating a list box problem
Next Topic: Simple PHP script - VMS problem
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 30 12:40:43 GMT 2024

Total time taken to generate the page: 0.02396 seconds