Re: 2 questions: Search in array and detect JS

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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?

You don't specifically what would change in the "AJAX page" (other than make use of AJAX) If it's possible, I would recommend you to serve the normal page and include a snippet to modify its behaviour, so you can "save the page reloads" (tipical use for AJAX), e.g.
  window.onload = function( ) {
    if ( document.frmTest ) {
      document.frmTest.onSubmit = function( ) {
        // verify values with ajax before submiting
      }
    }
  }
  // "normal version" of the page
This way you only change the behaviour when its supported (of course, you would also need a verification for Remote Scripting/AJAX support)

And I agree with the others about serving the "normal version" first, and redirecting via JS (when the behaviour is too different)

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 always....appreciated.

First, I would suggest you to re-analize why are you searching in an array (of course, you're the only here who knows the reason)

Second, you may encounter array_filter() useful, this function uses a callback user-defined function to "filter" the elements in a given array and build a second (which is the value it returns), so you may use this function along with strpos() (or some other)
  http://php.net/manual/en/function.array-filter.php
--
Atentamente,
J. Rafael Salazar Magaña
Innox - Innovación Inteligente
Tel: +52 (33) 3615 5348 ext. 205 / 01 800 2-SOFTWARE
http://www.innox.com.mx

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



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux