Solved

CGI -> PHP sorting.

Posted on 2002-07-06
9
299 Views
Last Modified: 2006-11-17
At the moment i have a cgi application that is resulting in the following code
results: 2
TITLE: title1
URL: http://whatever.com

TITLE: title2
URL: http://whatever.com

It just rattles off the information as it finds it, kind of like a search engine.

I can change how the output comes out as in
the URL: bit.
What im wanting is a php script that will get all this informaion (changes all the time), and show it in alphabetic order #-A-Z as a html link output.
e.g <a href=url>Title</a>

Please help me out i have been fooling around with this for weeks.



0
Comment
Question by:eraser3
  • 3
  • 3
9 Comments
 

Author Comment

by:eraser3
ID: 7133751
It rattles it off 1 after each other in the same web page Exactly like a search engine does.
0
 
LVL 7

Expert Comment

by:axis_img
ID: 7133911
"What im wanting is a php script that will get all this informaion"

Where is it going to get this information from? Is it going to be from a text file, database, or some other location? If it is a text file, what is the exact format of each line (please paste some example lines).

Let me know...
Barry
0
 

Author Comment

by:eraser3
ID: 7134423
Well its of a home made database of sorts. But i dont want the php to interface with the database files. I need it to just pick up the groups of text which comes out of the cgi program.
As i said before the cgi that is outputted is basically a search engine.
-------------------------------------------------------

Results:3 (this changeddepending on how mnay results)

Title: Billy
URL: http\\www.billy.com

(I can put a seperator here)

Title: Arthwe
URL: http\\www.idontknow.com

(I can put a seperator here)

-------------------------------------------------------

-------------------------------------------------------
 I didnt think it would be this hard. I believed that if i just stuck a delimeter inbetween the results i could split it. Because as i said before i can get the results to look like this
Arthwe,http\\www.idontknow.com
Seperator
Which should be easy to do but i dont know i just cant do it.
If you also wondering how the cgi file is being called you can either use a POST method or i just installed ? so you can go cgifile.cgi?keyword

Thanks for your help,
-Marc
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 7

Expert Comment

by:axis_img
ID: 7134437
"But i dont want the php to interface with the database files."

Yeah. I didn't mean that, really. I was just asking where PHP would need to get the information, and in what format. I now understand that it is basically just going to be a string of text that is returned by your cgi app. This should not be too much of a problem, but I am about to head out the door for the evening. I will check in tomorrow and post a possible solution for you.

Regards,
Barry
0
 

Author Comment

by:eraser3
ID: 7134459
Ok groovey thanks..
0
 
LVL 7

Accepted Solution

by:
axis_img earned 300 total points
ID: 7136099
k.. So give this a try, and let me know how it works for you. There are two files here: results.php and results.txt. Just put both of them in the same directory, and then load results.php in your browser. It should display the links and alphabetize them as requested. The results.txt file is just a means to test the script. The actual results that this script would parse through would come from your CGI app, but they should be in the same format as the results.txt file is.



results.txt (notice I use [DEL] as the delimiter for all of the fields)
--------------------------------------------------------
Results:3
[DEL]
Title: Grep TV
URL: http:\\www.grep.tv
[DEL]
Title: Experts-Exchange
URL: http:\\www.experts-exchange.com
[DEL]
Title: PHP
URL: http:\\www.php.net


results.php
--------------------------------------------------------
<?
$delimiter     = "[DEL]";
$results     = implode("\n", file("results.txt"));
$result_array     = explode($delimiter, $results);

// First value of the array is the Result Count
// I do not know if you need this or not, but I left it here anyway...
// If PHP does not need the result count, then just discard this part
$result_count     = str_replace("Results:", "", $result_array[0]);
$result_count     = trim($result_count);

// Remove the result count, so we only have the actual results left in the array
array_shift($result_array);

// Sort the array results alphabetically
usort($result_array, 'strcasecmp');

// Print out the proper link based on each result
foreach($result_array as $result) {
     $result     = trim($result);
     $link     = make_link($result);
     print "LINK: $link<p>";
}


function make_link($result_string) {
     return(preg_replace("~Title:\s+(.+)\s*URL:\s+(.+)\s*$~iU", "<a href='\\2' target='_blank'>\\1</a>", $result_string));
}
?>


Let me know if you have any questions, or if you want to make any modifications to this. I had to guess on how some of it worked on your end, since I don't have all of the details of what you need. Let me know what is missing.

Barry
0
 
LVL 11

Expert Comment

by:shmert
ID: 9643780
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Accept: axis_img
Please leave any comments here within the next seven days.
               
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
               
Sam Barnum
EE Cleanup Volunteer              
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

828 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