Solved

CGI -> PHP sorting.

Posted on 2002-07-06
9
304 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

 
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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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 …

636 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