473,703 Members | 2,643 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

function problems

could use some help with a function to clean up keywords in a url. I'm
expecting $keywords to equal 'coretta scott king' - the plus signs are
stripped out for search engine referrals. What am I doing wrong?
<?php

$referer = 'http://www.google.com/search?hl=en&q= coretta+scott+k ing';

function parse_keywords( $referer){
// Google, AllTheWeb, MSN, Freeserve, Altavista
if ((eregi("www.go ogle",$referer) ) or
(eregi("www.all theweb",$refere r)) or (eregi("search. msn",$referer) ) or
(eregi("ifind.f reeserve",$refe rer)) or
(eregi("altavis ta.com",$refere r))) {
preg_match("'q= (.*?)(&| )'si", " $url ", $keywords);
}
// HotBot, Lycos, Netscape, AOL
if ((eregi("www.ho tbot",$referer) ) or (eregi("search. lycos",$referer ))
or (eregi("search. netscape",$refe rer)) or
(eregi("aolsear ch.aol",$refere r))) {
preg_match("'qu ery=(.*?)(&| )'si", " $url ", $keywords);
}
// Yahoo
if ((eregi("yahoo. com",$referer) ) or (eregi("search. yahoo",$referer )))
{
preg_match("'p= (.*?)(&| )'si", " $url ", $keywords);
}
// Looksmart
if (eregi("looksma rt.com",$refere r)) {
preg_match("'ke y=(.*?)(&| )'si", " $url ", $keywords);
}
// DMOZ
if (eregi("search. dmoz",$referer) ) {
preg_match("'se arch=(.*?)(&| )'si", " $url ", $keywords);
}
// Ask
if (eregi("ask.co" ,$referer)) {
preg_match("'as k=(.*?)(&| )'si", " $url ", $keywords);
}

if (($keywords[1]!="") and ($keywords[1]!=" ")) {
$keywords=str_r eplace("+"," ",$keywords[1]);
}
return $keywords;
}
$keywords = parse_keywords( $referer);
echo $keywords;
?>

Feb 15 '06 #1
2 1669
could use some help with a function to clean up keywords in a url. I'm
expecting $keywords to equal 'coretta scott king' - the plus signs are
stripped out for search engine referrals. What am I doing wrong? <?php

$referer = 'http://www.google.com/search?hl=en&q= coretta+scott+k ing';

function parse_keywords( $referer){
// Google, AllTheWeb, MSN, Freeserve, Altavista
if ((eregi("www.go ogle",$referer) ) or
(eregi("www.all theweb",$refere r)) or (eregi("search. msn",$referer) ) or
(eregi("ifind.f reeserve",$refe rer)) or
(eregi("altavis ta.com",$refere r))) {
preg_match("'q= (.*?)(&| )'si", " $url ", $keywords);
}
.... more code snipped...
return $keywords;
}
$keywords = parse_keywords( $referer);
echo $keywords;


Question 1: what do you think the variable $url contains?
Question 2: why have you got error reporting turned off, which would
answer question 1?

---
Steve

Feb 15 '06 #2

az*****@gmail.c om wrote:
could use some help with a function to clean up keywords in a url. I'm
expecting $keywords to equal 'coretta scott king' - the plus signs are
stripped out for search engine referrals. What am I doing wrong?
<?php

$referer = 'http://www.google.com/search?hl=en&q= coretta+scott+k ing';

function parse_keywords( $referer){
// Google, AllTheWeb, MSN, Freeserve, Altavista
if ((eregi("www.go ogle",$referer) ) or
(eregi("www.all theweb",$refere r)) or (eregi("search. msn",$referer) ) or
(eregi("ifind.f reeserve",$refe rer)) or
(eregi("altavis ta.com",$refere r))) {
preg_match("'q= (.*?)(&| )'si", " $url ", $keywords);
}
// HotBot, Lycos, Netscape, AOL
if ((eregi("www.ho tbot",$referer) ) or (eregi("search. lycos",$referer ))
or (eregi("search. netscape",$refe rer)) or
(eregi("aolsear ch.aol",$refere r))) {
preg_match("'qu ery=(.*?)(&| )'si", " $url ", $keywords);
}
// Yahoo
if ((eregi("yahoo. com",$referer) ) or (eregi("search. yahoo",$referer )))
{
preg_match("'p= (.*?)(&| )'si", " $url ", $keywords);
}
// Looksmart
if (eregi("looksma rt.com",$refere r)) {
preg_match("'ke y=(.*?)(&| )'si", " $url ", $keywords);
}
// DMOZ
if (eregi("search. dmoz",$referer) ) {
preg_match("'se arch=(.*?)(&| )'si", " $url ", $keywords);
}
// Ask
if (eregi("ask.co" ,$referer)) {
preg_match("'as k=(.*?)(&| )'si", " $url ", $keywords);
}

if (($keywords[1]!="") and ($keywords[1]!=" ")) {
$keywords=str_r eplace("+"," ",$keywords[1]);
}
return $keywords;
}
$keywords = parse_keywords( $referer);
echo $keywords;
?>


Inside your function your use $url, which is undefined. Are you sure
you didn't mean to use $referer instead? Also, for performance, I'd
recommend changing some of your if((eregi... statements to else if(...
Once one of them evaluates to true he won't evaluate the others (which,
when using preg_*, can be expensive).

Feb 15 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
4963
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my webserver runs that part of the script (see attached file, snippet.php), though, it doesn't go through. I don't get an error message or anything...it just returns a "1" (whereas it should return a "0") as far as I can tell. I have read the PHP...
8
2100
by: Ares Lagae | last post by:
When adopting the coding style of the standard C++ library, you often run into naming problems because class names are lower case, and member functions do not have get/set prefixes. For example: - The class stringstream has a member function "string stringstream::str()". It would be more logical to name it "string stringstream::string()". - The class ios_base has a member function "locale ios_base::getloc()". It would be more logical to...
4
6090
by: Vitali Gontsharuk | last post by:
Hallo! When using the XPATH document() function to load a new XML document, we are coming across problems, because XALAN seems to have problems with absolute paths. XALAN always assumes that the path is relative to the current directory. So if we e.g. are in "c:\xslt_scripts" and are trying to load an XML file from "c:\xml_files\test.xml" it ist trying to open a file with the following absolute path:...
5
8796
by: Corky | last post by:
This works: db2 SELECT DISTINCT PROBLEM_OBJECTS.PROBLEM_ID FROM PROBLEM_OBJECTS INNER JOIN PROBLEMS ON PROBLEM_OBJECTS.PROBLEM_ID = PROBLEMS.PROBLEM_ID WHERE INTEGER(DAYS(CURRENT DATE) - DAYS(PROBLEMS.CLOSE_DATE)) = 365 AND PROBLEMS.CLOSE_DATE IS NOT NULL But this doesn't: db2 SELECT DISTINCT PROBLEM_OBJECTS.PROBLEM_ID FROM PROBLEM_OBJECTS
39
2192
by: zeus | last post by:
I know function overloading is not supported in C. I have a few questions about this: 1. Why? is it from technical reasons? if so, which? 2. why wasn't it introduced to the ANSI? 3. Is there any C implementation supporting this feature? I assume some of you will claim that there is no need in function overloading, so I would like to know your arguments too. Thanks,
31
3714
by: bilbothebagginsbab5 AT freenet DOT de | last post by:
Hello, hello. So. I've read what I could find on google(groups) for this, also the faq of comp.lang.c. But still I do not understand why there is not standard method to "(...) query the malloc package to find out how big an allocated block is". ( Question 7.27) Is there somwhere explained why - because it would seem to me, that free()
8
2684
by: ais523 | last post by:
I use this function that I wrote for inputting strings. It's meant to return a pointer to mallocated memory holding one input string, or 0 on error. (Personally, I prefer to use 0 to NULL when returning null pointers.) It looks pretty watertight to me, but my version of lint complains about use of deallocated pointers, etc. Is this code completely safe on all input, or have I missed something? /* Header files included in the program...
4
3792
by: Kelii | last post by:
Hi all, (WinXP Pro SP2, Access 2003) I'm using Dev Ashish's fRefreshLinks function from AccessWeb (http://www.mvps.org/access/tables/tbl0009.htm) to relink tables in my front end to one of several back end files. When I first dropped in the function I was getting an error on one of my tables saying "Couldn't relink table, table doesn't exist"... or
28
3801
by: gnuist006 | last post by:
I have some code like this: (if (test) (exit) (do something)) or (if (test)
53
8397
by: souporpower | last post by:
Hello All I am trying to activate a link using Jquery. Here is my code; <html> <head> <script type="text/javascript" src="../../resources/js/ jquery-1.2.6.js"</script> <script language="javascript" type="text/javascript">
0
8747
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9240
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8998
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7849
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6585
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4675
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2430
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2056
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.