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+king';
function parse_keywords($referer){
// Google, AllTheWeb, MSN, Freeserve, Altavista
if ((eregi("www.google",$referer)) or
(eregi("www.alltheweb",$referer)) or (eregi("search.msn",$referer)) or
(eregi("ifind.freeserve",$referer)) or
(eregi("altavista.com",$referer))) {
preg_match("'q=(.*?)(&| )'si", " $url ", $keywords);
}
// HotBot, Lycos, Netscape, AOL
if ((eregi("www.hotbot",$referer)) or (eregi("search.lycos",$referer))
or (eregi("search.netscape",$referer)) or
(eregi("aolsearch.aol",$referer))) {
preg_match("'query=(.*?)(&| )'si", " $url ", $keywords);
}
// Yahoo
if ((eregi("yahoo.com",$referer)) or (eregi("search.yahoo",$referer)))
{
preg_match("'p=(.*?)(&| )'si", " $url ", $keywords);
}
// Looksmart
if (eregi("looksmart.com",$referer)) {
preg_match("'key=(.*?)(&| )'si", " $url ", $keywords);
}
// DMOZ
if (eregi("search.dmoz",$referer)) {
preg_match("'search=(.*?)(&| )'si", " $url ", $keywords);
}
// Ask
if (eregi("ask.co",$referer)) {
preg_match("'ask=(.*?)(&| )'si", " $url ", $keywords);
}
if (($keywords[1]!="") and ($keywords[1]!=" ")) {
$keywords=str_replace("+"," ",$keywords[1]);
}
return $keywords;
}
$keywords = parse_keywords($referer);
echo $keywords;
?> 2 1650 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+king';
function parse_keywords($referer){ // Google, AllTheWeb, MSN, Freeserve, Altavista if ((eregi("www.google",$referer)) or (eregi("www.alltheweb",$referer)) or (eregi("search.msn",$referer)) or (eregi("ifind.freeserve",$referer)) or (eregi("altavista.com",$referer))) { 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 az*****@gmail.com 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+king';
function parse_keywords($referer){ // Google, AllTheWeb, MSN, Freeserve, Altavista if ((eregi("www.google",$referer)) or (eregi("www.alltheweb",$referer)) or (eregi("search.msn",$referer)) or (eregi("ifind.freeserve",$referer)) or (eregi("altavista.com",$referer))) { preg_match("'q=(.*?)(&| )'si", " $url ", $keywords); } // HotBot, Lycos, Netscape, AOL if ((eregi("www.hotbot",$referer)) or (eregi("search.lycos",$referer)) or (eregi("search.netscape",$referer)) or (eregi("aolsearch.aol",$referer))) { preg_match("'query=(.*?)(&| )'si", " $url ", $keywords); } // Yahoo if ((eregi("yahoo.com",$referer)) or (eregi("search.yahoo",$referer))) { preg_match("'p=(.*?)(&| )'si", " $url ", $keywords); } // Looksmart if (eregi("looksmart.com",$referer)) { preg_match("'key=(.*?)(&| )'si", " $url ", $keywords); } // DMOZ if (eregi("search.dmoz",$referer)) { preg_match("'search=(.*?)(&| )'si", " $url ", $keywords); } // Ask if (eregi("ask.co",$referer)) { preg_match("'ask=(.*?)(&| )'si", " $url ", $keywords); }
if (($keywords[1]!="") and ($keywords[1]!=" ")) { $keywords=str_replace("+"," ",$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). This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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:...
|
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...
|
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) -...
|
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...
|
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...
|
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...
|
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...
|
by: gnuist006 |
last post by:
I have some code like this:
(if (test)
(exit)
(do something))
or
(if (test)
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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...
| |