Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

CGI -> PHP sorting.

Posted on 2002-07-06
9
Medium Priority
?
305 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 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

 
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

Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

730 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