Re: [PHP] 2 questions: Search in array and detect JS

2006-04-17 Thread Jochem Maas

1. I'm not the original poster (I wasn't asking a question)
2. don't post me or anyone else 'offlist' unless asked
3. WTF are you talking about?
4. if you say 'First' then that assumes there is a 'Second'
coming. (that's sounds kinda funny given it was just Easter)

suresh kumar wrote:

First,
 If u want to search work richard hassed .first
split the word as richard and hassed by using
split() and store it in array.and use select like
command to search individual word stored in array.this
 type of searching is followed in google.


   A.suresh 


--- Jochem Maas [EMAIL PROTECTED] wrote:



don't know if someone mentioned it already but i was
digging around in the docs
for something completely different and bumped into
this:

preg_grep() [http://php.net/preg_grep]

and I thought of your question, might be just what
your looking for.

I can't remember having come across this func before
- learn something new every day :-)


Ryan A wrote:


Hi,
Like the subject says; I have two questions:

1) Is it possible to detect JavaScript via php...


and yes I do know that JS


is client side while PHP is server...but how else


to do it?


The reason I ask is before serving an AJAX page I


would like to make sure JS


is enabled, if not, serve the other normal


page... I am sure I am not the


first person to come accross this little problem,


how did you solve it?


I have seen some suggestions on google like having


a hidden form field  and


using  js to put a value in it, if it exists when


the form is sent then JS


is on..if not, its not... but that method is not


the best in an AJAX


situation...right?


2) How can I search in an array for a particular


word?


eg: in an array movie I have this kind of data:
movie_name= some movie
cast= Jim Carrey, Richard Pryor, Eddie Murphy

I want to search on either Richard or Richard


Pryor (must be case


insensitive too)
something like a SELECT with a LIKE %% statement

I have been fooling around with in_array() but not


getting anywhere


fast. am I on the right track?
Links, code examples or advise would be as


alwaysappreciated.


Thanks,
Ryan



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php








__ 
Yahoo! India Matrimony: Find your partner now. Go to http://yahoo.shaadi.com


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] 2 questions: Search in array and detect JS

2006-04-16 Thread Jochem Maas

don't know if someone mentioned it already but i was digging around in the docs
for something completely different and bumped into this:

preg_grep() [http://php.net/preg_grep]

and I thought of your question, might be just what your looking for.

I can't remember having come across this func before - learn something new 
every day :-)


Ryan A wrote:

Hi,
Like the subject says; I have two questions:

1) Is it possible to detect JavaScript via php... and yes I do know that JS
is client side while PHP is server...but how else to do it?
The reason I ask is before serving an AJAX page I would like to make sure JS
is enabled, if not, serve the other normal page... I am sure I am not the
first person to come accross this little problem, how did you solve it?

I have seen some suggestions on google like having a hidden form field  and
using  js to put a value in it, if it exists when the form is sent then JS
is on..if not, its not... but that method is not the best in an AJAX
situation...right?


2) How can I search in an array for a particular word?

eg: in an array movie I have this kind of data:
movie_name= some movie
cast= Jim Carrey, Richard Pryor, Eddie Murphy

I want to search on either Richard or Richard Pryor (must be case
insensitive too)
something like a SELECT with a LIKE %% statement

I have been fooling around with in_array() but not getting anywhere
fast. am I on the right track?
Links, code examples or advise would be as alwaysappreciated.

Thanks,
Ryan



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] 2 questions: Search in array and detect JS

2006-04-15 Thread Stut

Ryan A wrote:

1) Is it possible to detect JavaScript via php... and yes I do know that JS
is client side while PHP is server...but how else to do it?
The reason I ask is before serving an AJAX page I would like to make sure JS
is enabled, if not, serve the other normal page... I am sure I am not the
first person to come accross this little problem, how did you solve it?


The way I do this is to serve the 'notmal page' first, but with the 
following snippet of JS in it...


script language=javascript
!--
location.href = '/url/for/ajax/page.php';
--
/script

That way if they have JS enabled they'll get sent to the AJAX page. If 
not they stay on the 'normal page'.



2) How can I search in an array for a particular word?

eg: in an array movie I have this kind of data:
movie_name= some movie
cast= Jim Carrey, Richard Pryor, Eddie Murphy

I want to search on either Richard or Richard Pryor (must be case
insensitive too)
something like a SELECT with a LIKE %% statement

I have been fooling around with in_array() but not getting anywhere
fast. am I on the right track?
Links, code examples or advise would be as alwaysappreciated.


You should be able to craft some combination of array_walk and a custom 
function that checks each element with stristr to do what you need.


-Stut

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] 2 questions: Search in array and detect JS

2006-04-15 Thread Ryan A
Hey Stut,
Thanks for replying.

---


The way I do this is to serve the 'notmal page' first, but with the
following snippet of JS in it...

script language=javascript
!--
 location.href = '/url/for/ajax/page.php';
--
/script--Makes sense and pretty easy, this was
suggested a while back, since you have supported itI think I'll start using
this method.--- You should be able to craft some combination
of array_walk and a custom
function that checks each element with stristr to do what you need.
-Actually, I solved this thanks to Richard from the list who
suggested strpos, a function I had never usedbefore ( Tedd from the list
gave me the same suggestion as you to use stristr, I didnt want to use
stristr as its a bit expensive esp with a really large array) the problem I
ran into was that strpos is a php5 functionbut reading the user
contributed articles on strpos at thephp site I got the code that does
exactly that in 2-3 linesCheers!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] 2 questions: Search in array and detect JS

2006-04-15 Thread Chrome
[snip]
script language=javascript
!--
 location.href = '/url/for/ajax/page.php';
--
/script
[/snip]

My only concern with this method is that it constitutes an exit trap... For
example, if a user connects to your index page from, say, Google they will
be redirected over to your Ajax page... All good, except if they click Back
to return to the SE page they will immediately bounce back to your Ajax page

Something to consider might be:

noscript
Sorry! This page requires Javascript to function properly! Please enable it
or get a decent browser
/noscript

!-- Normal page functions --

I haven't tested it so there is a chance it's fiction :)

Of course, if web standards aren't a concern it makes no difference

HTH

Dan

 
---
http://chrome.me.uk
 
-Original Message-
From: Ryan A [mailto:[EMAIL PROTECTED] 
Sent: 15 April 2006 14:26
To: php
Cc: Stut
Subject: Re: [PHP] 2 questions: Search in array and detect JS

Hey Stut,
Thanks for replying.

---


The way I do this is to serve the 'notmal page' first, but with the
following snippet of JS in it...

script language=javascript
!--
 location.href = '/url/for/ajax/page.php';
--
/script--Makes sense and pretty easy, this was
suggested a while back, since you have supported itI think I'll start using
this method.--- You should be able to craft some combination
of array_walk and a custom
function that checks each element with stristr to do what you need.
-Actually, I solved this thanks to Richard from the list who
suggested strpos, a function I had never usedbefore ( Tedd from the list
gave me the same suggestion as you to use stristr, I didnt want to use
stristr as its a bit expensive esp with a really large array) the problem I
ran into was that strpos is a php5 functionbut reading the user
contributed articles on strpos at thephp site I got the code that does
exactly that in 2-3 linesCheers!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


__ NOD32 1.1490 (20060415) Information __

This message was checked by NOD32 antivirus system.
http://www.eset.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] 2 questions: Search in array and detect JS

2006-04-15 Thread tedd

Something to consider might be:

noscript
Sorry! This page requires Javascript to function properly! Please enable it
or get a decent browser
/noscript

!-- Normal page functions --

I haven't tested it so there is a chance it's fiction :)

Of course, if web standards aren't a concern it makes no difference

Dan



It works and if you want it to validate, just enclose the paragraph 
in p/p, like so:


noscript
p
Sorry! This page requires Javascript to function properly! Please enable it
or get a decent browser.
/p
/noscript

To bad that php within those tags is read regardless or we would have 
an easy way to detect js.


tedd
--

http://sperling.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] 2 questions: Search in array and detect JS

2006-04-15 Thread Chrome
How about

?php $js = true; ?

noscript
?php $js = false; ?
/noscript

?php
if ($js){
// whizzy Ajax code (or file include)
} else {
// generic warning (or include non-JS base file)
}
?

I know that would work but does it give the desired effect?

Dan

 
---
http://chrome.me.uk
 

-Original Message-
From: tedd [mailto:[EMAIL PROTECTED] 
Sent: 15 April 2006 15:10
To: Chrome; 'Ryan A'; 'php'
Cc: 'Stut'
Subject: RE: [PHP] 2 questions: Search in array and detect JS

Something to consider might be:

noscript
Sorry! This page requires Javascript to function properly! Please enable it
or get a decent browser
/noscript

!-- Normal page functions --

I haven't tested it so there is a chance it's fiction :)

Of course, if web standards aren't a concern it makes no difference

Dan


It works and if you want it to validate, just enclose the paragraph 
in p/p, like so:

noscript
p
Sorry! This page requires Javascript to function properly! Please enable it
or get a decent browser.
/p
/noscript

To bad that php within those tags is read regardless or we would have 
an easy way to detect js.

tedd
-- 


http://sperling.com

__ NOD32 1.1490 (20060415) Information __

This message was checked by NOD32 antivirus system.
http://www.eset.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] 2 questions: Search in array and detect JS

2006-04-15 Thread cajbecu
In your script, $js will be false false!

Chrome wrote:
 How about
 
 ?php $js = true; ?
 
 noscript
   ?php $js = false; ?
 /noscript
 
 ?php
 if ($js)  {
   // whizzy Ajax code (or file include)
 } else {
   // generic warning (or include non-JS base file)
 }
 ?
 
 I know that would work but does it give the desired effect?
 
 Dan
 
  
 ---
 http://chrome.me.uk
  
 
 -Original Message-
 From: tedd [mailto:[EMAIL PROTECTED] 
 Sent: 15 April 2006 15:10
 To: Chrome; 'Ryan A'; 'php'
 Cc: 'Stut'
 Subject: RE: [PHP] 2 questions: Search in array and detect JS
 
 Something to consider might be:

 noscript
 Sorry! This page requires Javascript to function properly! Please enable it
 or get a decent browser
 /noscript

 !-- Normal page functions --

 I haven't tested it so there is a chance it's fiction :)

 Of course, if web standards aren't a concern it makes no difference

 Dan
 
 
 It works and if you want it to validate, just enclose the paragraph 
 in p/p, like so:
 
 noscript
 p
 Sorry! This page requires Javascript to function properly! Please enable it
 or get a decent browser.
 /p
 /noscript
 
 To bad that php within those tags is read regardless or we would have 
 an easy way to detect js.
 
 tedd

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] 2 questions: Search in array and detect JS

2006-04-15 Thread Chrome
Yep just realised my half-witted mistake (and what tedd was getting at)

Sorry about that

Dan

 
---
http://chrome.me.uk
 

-Original Message-
From: cajbecu [mailto:[EMAIL PROTECTED] 
Sent: 15 April 2006 15:40
To: Chrome
Cc: 'tedd'; 'Ryan A'; 'php'; 'Stut'
Subject: Re: [PHP] 2 questions: Search in array and detect JS

In your script, $js will be false false!

Chrome wrote:
 How about
 
 ?php $js = true; ?
 
 noscript
   ?php $js = false; ?
 /noscript
 
 ?php
 if ($js)  {
   // whizzy Ajax code (or file include)
 } else {
   // generic warning (or include non-JS base file)
 }
 ?
 
 I know that would work but does it give the desired effect?
 
 Dan
 
  
 ---
 http://chrome.me.uk
  
 
 -Original Message-
 From: tedd [mailto:[EMAIL PROTECTED] 
 Sent: 15 April 2006 15:10
 To: Chrome; 'Ryan A'; 'php'
 Cc: 'Stut'
 Subject: RE: [PHP] 2 questions: Search in array and detect JS
 
 Something to consider might be:

 noscript
 Sorry! This page requires Javascript to function properly! Please enable
it
 or get a decent browser
 /noscript

 !-- Normal page functions --

 I haven't tested it so there is a chance it's fiction :)

 Of course, if web standards aren't a concern it makes no difference

 Dan
 
 
 It works and if you want it to validate, just enclose the paragraph 
 in p/p, like so:
 
 noscript
 p
 Sorry! This page requires Javascript to function properly! Please enable
it
 or get a decent browser.
 /p
 /noscript
 
 To bad that php within those tags is read regardless or we would have 
 an easy way to detect js.
 
 tedd


__ NOD32 1.1490 (20060415) Information __

This message was checked by NOD32 antivirus system.
http://www.eset.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] 2 questions: Search in array and detect JS

2006-04-15 Thread fabien champel
js is client-side, php server side...
it can't work

fabien

 Chrome wrote:
  How about
 
  ?php $js = true; ?
 
  noscript
?php $js = false; ?
  /noscript
 
  ?php
  if ($js)  {
// whizzy Ajax code (or file include)
  } else {
// generic warning (or include non-JS base file)
  }
  ?
 
  I know that would work but does it give the desired effect?
 
  Dan
 
 
  ---
  http://chrome.me.uk

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] 2 questions: Search in array and detect JS

2006-04-15 Thread fabien champel
for js detection, you can use that in a previous page :

script type=text/javascript
document.write('a href=ajax-page.htmlpage/a');
/script
noscripta href=simple-page.htmlpage/a/noscript


it is simple, and work fine.
no need to have cookies enable

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] 2 questions: Search in array and detect JS

2006-04-15 Thread Ryan A
Hey,
Thanks for replying.




for js detection, you can use that in a previous page :

script type=text/javascript
document.write('a href=ajax-page.htmlpage/a');
/script
noscripta href=simple-page.htmlpage/a/noscript


it is simple, and work fine.
no need to have cookies enable-Nice, most of the
methods discussed focuses on the fact that you are sending this person from
a previous page,eg:index.php to- contact_us.phpbut what if you are using
AJAX on the first page (eg: index.php)then isnt the  location.href =
'/url/for/ajax/index2/page.php'; the best solution?Cheers!Ryan

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] 2 questions: Search in array and detect JS

2006-04-15 Thread John Wells
On 4/14/06, Ryan A [EMAIL PROTECTED] wrote:
 The reason I ask is before serving an AJAX page I would like to make sure JS
 is enabled, if not, serve the other normal page... I am sure I am not the
 first person to come accross this little problem, how did you solve it?

Dan eluded to a big problem here, regarding the potential exit trap
of redirecting a user to a different page.  However there's even more
at stake--this solution would require you to manage *two* versions of
your page.  Come on, we can do better than that...

What you should do is create your normal page as is, and then write
your javascript to attach itself to whatever things you want to
AJAXify on that page.  Research unobtrusive javascript, it should
get you in the right direction.

The idea is, you build your page to function normally without any
javascript.  Then you attempt to hook up the javascript via your
page's onload event (there are other methods too I believe, Google
it).  If javascript is enabled, then the javascript will be hooked in;
if not, then no AJAX will be loaded, but your page will still function
as needed.

HTH,

John W

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] 2 questions: Search in array and detect JS

2006-04-14 Thread tedd

Ryan:

First question. Technically no, you can't detect js from php.

However, I read where one can detect if a user has cookies on by 
sending a cookie and then reading it back. And considering that you 
can send a cookie via js, you could do that. However, that would mean 
that the user had to have both js and cookies on.


Second question. Unless I don't understand the problem, simply use a 
loop and stristr().


See; http://www.weberdev.com/stristr

HTH's

tedd

---
At 7:24 PM +0200 4/14/06, Ryan A wrote:

Hi,
Like the subject says; I have two questions:

1) Is it possible to detect JavaScript via php... and yes I do know that JS
is client side while PHP is server...but how else to do it?
The reason I ask is before serving an AJAX page I would like to make sure JS
is enabled, if not, serve the other normal page... I am sure I am not the
first person to come accross this little problem, how did you solve it?

I have seen some suggestions on google like having a hidden form field  and
using  js to put a value in it, if it exists when the form is sent then JS
is on..if not, its not... but that method is not the best in an AJAX
situation...right?


2) How can I search in an array for a particular word?

eg: in an array movie I have this kind of data:
movie_name= some movie
cast= Jim Carrey, Richard Pryor, Eddie Murphy

I want to search on either Richard or Richard Pryor (must be case
insensitive too)
something like a SELECT with a LIKE %% statement

I have been fooling around with in_array() but not getting anywhere
fast. am I on the right track?
Links, code examples or advise would be as alwaysappreciated.

Thanks,
Ryan

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--

http://sperling.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] 2 questions: Search in array and detect JS

2006-04-14 Thread Robert Cummings
On Fri, 2006-04-14 at 13:34, tedd wrote:
 Ryan:
 
 First question. Technically no, you can't detect js from php.
 
 However, I read where one can detect if a user has cookies on by 
 sending a cookie and then reading it back. And considering that you 
 can send a cookie via js, you could do that. However, that would mean 
 that the user had to have both js and cookies on.

It is probably a better to approach this backwards. So load the non JS
page, and within it detect if javascript is enabled, in which case
perform a javascript based redirect to the Ajax enabled page.

 Second question. Unless I don't understand the problem, simply use a 
 loop and stristr().

stripos() is a better candidate since you are only looking for the
string and it skips the extra processing of stristr().

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] 2 questions: Search in array and detect JS

2006-04-14 Thread Ryan A
Hey Tedd / Robert,
Thanks for replying.

--
 Tedd:
However, I read where one can detect if a user has cookies on by
sending a cookie and then reading it back. And considering that you
can send a cookie via js, you could do that. However, that would mean
that the user had to have both js and cookies on.-

Yep, two things to worry about instead of one.


 
Tedd:
Second question. Unless I don't understand the problem, simply use a
loop and stristr().-stristr() is a bit expensive, was
not too sure if I wanted to use that because I will be lookingin a array of
hundreds of movies (maybe even thousands)-- Robert:It is
probably a better to approach this backwards. So load the non JS
page, and within it detect if javascript is enabled, in which case
perform a javascript based redirect to the Ajax enabled
page.-Hmmm, makes sense and I have not used this method
beforewill def check it out.-- stripos() is a better
candidate since you are only looking for the
string and it skips the extra processing of
stristr().--I am more familier with strstr and stristr
but will give stripos a look-see  too..Thanks,Ryan

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php