Forum Moderators: coopster

Message Too Old, No Replies

preg match question

preg match php

         

frogz

7:20 am on Jan 10, 2009 (gmt 0)

10+ Year Member



if (preg_match("/\google\b/i", $_SERVER['REQUEST_URI'])) {
print "yahooo";
} else {
print "hello";
}

cannot match anything within the query url?

so [domain.com...]

will return yahooo

why doesnt this work?

wildbest

11:31 am on Jan 10, 2009 (gmt 0)

10+ Year Member



Maybe you should try:
if (preg_match("/\bgoogle\b/i", $_SERVER['REQUEST_URI']))

frogz

11:50 am on Jan 10, 2009 (gmt 0)

10+ Year Member



hello wildbest!
thank you for your reply,

unfortunately to no avail, it still doesn't recognize the characters in the URL.

I even tried

if (preg_match("post_id", $_SERVER['REQUEST_URI']))

but still refers to "else" sending default, when applicable.

thank you for taking your time to respond previously.

frogz

11:51 am on Jan 10, 2009 (gmt 0)

10+ Year Member



woops! "post_id" = "google" in above scenario.

wildbest

12:23 pm on Jan 10, 2009 (gmt 0)

10+ Year Member



cannot match anything within the query url?

so [domain.com...]
$_SERVER['REQUEST_URI'] is /google.html
$_SERVER["SCRIPT_URI"] is [domain.com...]

Where is the "post_id" in [domain.com...] Isn't that actually a query string in $_SERVER["QUERY_STRING"]?

wildbest

12:35 pm on Jan 10, 2009 (gmt 0)

10+ Year Member



I even tried if (preg_match("post_id", $_SERVER['REQUEST_URI']))

You're missing the delimiters "/" for the pattern string to search for!

preg_match("/google/i", $_SERVER['REQUEST_URI'])

frogz

12:38 pm on Jan 10, 2009 (gmt 0)

10+ Year Member



yes sorry for the confusion,

i meant i tried:
if (preg_match("google, $_SERVER['REQUEST_URI'])) {
print "yahooo";
} else {
print "hello";
}

yes, "google" would be the word in the query string in which I am trying initiate the response.

I made an error and typed: if (preg_match("post_id", $_SERVER['REQUEST_URI']))

where "post_id" shouldve been "google"

my apologies for any confusion

frogz

12:40 pm on Jan 10, 2009 (gmt 0)

10+ Year Member



I also tried your suggestion as well, it doesnt initiate a response

wildbest

1:00 pm on Jan 10, 2009 (gmt 0)

10+ Year Member



I also tried your suggestion as well, it doesnt initiate a response

Dont forget the <?php...?> for your php scripts! :)

<?php
if (stripos ('google', $_SERVER['REQUEST_URI']) === true) {
echo "yahooo";
} else {
echo "hello";
}
?>

frogz

1:14 pm on Jan 10, 2009 (gmt 0)

10+ Year Member



still doesnt work, I did use the <?php ?> tyvm :P

the source shows no sign of the script, and it does use "else" properly (properly displays: hello), when the url with "google" in it is present, it still resorts to the "else" argument, "hello". Where it should then switch to "yahooo", but doesnt (still)

thanks again for your help

wildbest

1:23 pm on Jan 10, 2009 (gmt 0)

10+ Year Member



Put this function on the same php page and tell me what value do you see for _SERVER['REQUEST_URI'] variable?

<?php

echo phpinfo();

?>

frogz

1:30 pm on Jan 10, 2009 (gmt 0)

10+ Year Member



lol

System Linux2.********** Thu Nov 20 21:57:00 UTC 2008 i686
Build Date
Server API Apache ****** Handler
Configuration File (php.ini) Path *********
Loaded Configuration File *********Zend/etc/php.ini
Scan this dir for additional .ini files

thnx again for your help

wildbest

1:32 pm on Jan 10, 2009 (gmt 0)

10+ Year Member



This php script should be placed on the same page - google.html
You should, however, process .html file as php files.
To ensure this you have to place the following line in your .htaccess file:

AddHandler x-httpd-php .html

I'm sorry I didn't spot that irregularity on your original post.

frogz

1:32 pm on Jan 10, 2009 (gmt 0)

10+ Year Member



she definitely works! (was laughing because its a kinda busy server, they were prob like "#*$!"

frogz

1:34 pm on Jan 10, 2009 (gmt 0)

10+ Year Member



I already have this in my htaccess:

AddType application/x-httpd-php .html .htm

ty

frogz

1:35 pm on Jan 10, 2009 (gmt 0)

10+ Year Member



this is what i couldnt figure out either

frogz

1:39 pm on Jan 10, 2009 (gmt 0)

10+ Year Member



still cannot get it to recognize "google" in the url and print,

thanks for your time

wildbest

1:42 pm on Jan 10, 2009 (gmt 0)

10+ Year Member



So, where we are now? :)
Have 4 min more and I'm off...

frogz

1:43 pm on Jan 10, 2009 (gmt 0)

10+ Year Member



back to square one I'm afraid

the php response is working correctly, just cant seem to get it to retrieve from the url for some reason.

frogz

1:44 pm on Jan 10, 2009 (gmt 0)

10+ Year Member



thank you for all your efforts!

wildbest

1:45 pm on Jan 10, 2009 (gmt 0)

10+ Year Member



If still can't see google in your _SERVER['REQUEST_URI'] that most probably means it is not there! And you haven't still answered my question what do you see as _SERVER['REQUEST_URI'] variable?

frogz

1:47 pm on Jan 10, 2009 (gmt 0)

10+ Year Member



im sorry i didnt echo that variable, I was terrified my server info was displayed on the public forums.. I will check

wildbest

1:48 pm on Jan 10, 2009 (gmt 0)

10+ Year Member



Just

echo $_SERVER['REQUEST_URI'];

and tell me what do you see?

frogz

1:49 pm on Jan 10, 2009 (gmt 0)

10+ Year Member



there a way i can just echo that without displaying all my server info

frogz

1:50 pm on Jan 10, 2009 (gmt 0)

10+ Year Member



ok

frogz

1:51 pm on Jan 10, 2009 (gmt 0)

10+ Year Member



k sorry have to clear cahe too, i see the URL! :)

frogz

1:53 pm on Jan 10, 2009 (gmt 0)

10+ Year Member



the url is present and changes accordingly :)

frogz

1:55 pm on Jan 10, 2009 (gmt 0)

10+ Year Member



so the variable works fine, but it doesnt recognize my arguments still..

thanks again!

wildbest

2:00 pm on Jan 10, 2009 (gmt 0)

10+ Year Member



Of course, the phpinfo function should be removed immediately from all your active pages.

What is the exact response of:
echo $_SERVER['REQUEST_URI'];

It should be "/google.html"

frogz

2:01 pm on Jan 10, 2009 (gmt 0)

10+ Year Member



specifically it shows:

/forums/google.html

but not recognizing the arguments

regards, frogz

This 59 message thread spans 2 pages: 59