Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

CGI -> PHP sorting.

Posted on 2002-07-06
9
Medium Priority
?
306 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 1200 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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.
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.
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 …
Suggested Courses

972 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