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

Home » Imported messages » comp.lang.php » My first PHP Script...
Show: Today's Messages :: Unread Messages :: Polls :: Message Navigator
| Subscribe to topic | Bookmark topic 
Switch to threaded view of this topic Create a new topic Submit Reply
My first PHP Script... [message #175797] Wed, 26 October 2011 19:26 Go to next message
SpreadTooThin is currently offline  SpreadTooThin
Messages: 3
Registered: October 2011
Karma: 0
Junior Member
add to buddy list
ignore all messages by this user
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] Wed, 26 October 2011 21:00 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
remove from buddy list
ignore all messages by this user
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] Wed, 26 October 2011 23:22 Go to previous messageGo to next message
SpreadTooThin is currently offline  SpreadTooThin
Messages: 3
Registered: October 2011
Karma: 0
Junior Member
add to buddy list
ignore all messages by this user
> 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] Wed, 26 October 2011 23:31 Go to previous messageGo to next message
SpreadTooThin is currently offline  SpreadTooThin
Messages: 3
Registered: October 2011
Karma: 0
Junior Member
add to buddy list
ignore all messages by this user
> 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...
Message by Jerry Stuckle is ignored  [reveal message]  [reveal all messages by Jerry Stuckle]  [stop ignoring this user] Go to previous message
Quick Reply
Formatting Tools:   
  Switch to threaded view of this topic Create a new topic
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: Wed Oct 09 06:06:51 EDT 2024

Total time taken to generate the page: 0.06386 seconds