Solved

CGI -> PHP sorting.

Posted on 2002-07-06
9
291 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
Comment Utility
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
Comment Utility
"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
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 7

Expert Comment

by:axis_img
Comment Utility
"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
Comment Utility
Ok groovey thanks..
0
 
LVL 7

Accepted Solution

by:
axis_img earned 300 total points
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now