Jump to content

bibby

Members
  • Posts

    171
  • Joined

  • Last visited

    Never

Posts posted by bibby

  1. johnny86's would work.  At the same time, I was posting:

     

    $emailsToSend = array();
    foreach( $myarray as $service)
    {
       $e = $emails_array[$service];
       if($e)
           $emailsToSend[$service]=$e;
    }

     

    Does this do what you need?

     

    What can also do with your checkboxes is create an array in the post using a specific value  ( ;  the value does not have to be the string 'on' ).

     

    <input type="checkbox" name="services[]" value="Landscaping" />
    <input type="checkbox" name="services[]" value="Blah" />
    

     

    That'll post $_POST['services'] as an array instead of a string.

  2. Long answer, sorry..

    coupla things.

    first I'll answer the question, then offer what might be a better solution (though it takes more work).

     

    To detect the presence of a comma, you can use strpos or preg_match (and other fxns).

    strpos returns the position of the first occurrence of a string within a string, which could be 0. This is not to be mistaken for FALSE (return for no match), but in the "last, first" scenario it's probably not applicable.

     

    $hasComma = FALSE != strpos($trimmed, ',');
    # or
    $hasComma = preg_match('/,/',$trimmed,$m);

     

    or, you could just explode on the comma and count the result.

    $parts = explode(',', $trimmed);
    $hasComma = count($parts)>1;

     

    if there was a comma, and you're ok with assuming the user put in "last, first"  (also assuming/checking that count($parts)==2 ),  you can flip like so.

     

    list( $first, $last ) = $parts;
    if( $hasComma )
       list($last, $first) = array($first, $last);

     

    doing any exploding at all, you might want to trim all the parts so that you might reconstruct them in a controlled manner.

     

    $parts = array_map("trim", $parts);
    // I also like to filter empty parts
    $parts = array_values( array_filter( $parts ));

     

    Then your search term can be reconstructed

     $term = join(' ',array($first, $last));

     

    ----------------

     

    Now, I've gotta say that I don't think you've got an ideal search. What you might want to is break the search term apart (by space, comma, etc) and query an index of individual words. This is how you can rank of "relevance" and offer more results than you would have if the user misspelled their search term (which 5%-15% of users will always do).

     

    By "index" I mean a new table containing "terms" and their associative artist_ids.

    Let's take an example data set of three artists:

     

    1- Johnny Cash

    2- Sweep the Leg Johnny

    3- Clean Sweep

     

    Ignoring "the", our index of unique words is:

    Johnny

    Cash

    Sweep

    Leg

    Clean

     

    The linking table could look like:

    _term_|_artist_id_

    Johnny | 1

    Cash | 1

    Sweep | 2

    Leg | 2

    Johnny | 2

    Clean | 3

    Sweep | 3

     

    Gather up possible matches for each word, paying special attention to when the same records appear. That should increase their relevance. Misses should decrease the "score". Then present your results in order of score. It's often better to show more results than fewer.

     

    Before, a search for 'Sweep Johnny' would net 0 results, but we've all come to expect the search to be more lenient with our brevity. If we searched an index for each word, I'd get all three results, but I'd get exactly what I was looking for on the top.

     

    #1  Sweep the Leg Johnny  (100% 2/2)

    #2  Johnny Cash  (50% 1/2)

    #3  Clean Sweep (50% 1/2)

     

  3. I like sprintf and vsprintf for this -- more separation. Just another option in a sea of many.

     

    $q = "UPDATE members SET logfile = '%s admin logged into long2ip(%s)' WHERE username='%s'";
    $q = vsprintf($q, array(
    mysql_real_escape_string($playerlog),
    $ip,
    mysql_real_escape_string($player),
    ));

  4. The best guess that I have as to why the list of arguments provided by __call is an array is a matter on convenience. The arity of __call is always 2 ( http://dictionary.die.net/arity ),  __call( string $methodName, array $arguments), but you can call a method that does not exist using zero or more arguments without limitations. Packing them neatly into an array is the only option, since __call is meant to handle any situation where a method that does not exist is called, regardless of how many arguments are given.

     

    If you are using the undefined method setFirstName as a proxy for a set method that does exist or pass it onto another object within scope, you can call call_user_func_array to invoke that method using the arguments array as-is.

     

    call_user_func_array(array($class, $method), $argArray)

     

    Otherwise, you'll just have to deal with your arguments as an array.

     

    $foo->methodDoesNotExist( "foo", "bar", "baz" );
    //  __call picks it up  (  __call( $method, $args )  )

    (in __call)

    var_dump( $method, $args );
    /* ==
    string "methodDoesNotExist"  // $method
    array(3)(   // $args
    [0] => "foo",
    [1] => "bar",
    [2] => "baz"
    );
    */
    

     

  5. If the page within the iframe is on the same domain as the top page,  then it's document.cookie , just as it is on top.

     

    If the iframe is points to a different domain, then the browser won't let you. That's cross site scripting, and can be evil.

  6. scandir will also have the "files"  '.' (here) and '..' (parent directory), be sure to filter those out. The directory will more than likely see its modified time updated when one of its files does.

     

    I like is_file for as well, because file_exists() on a directory will be TRUE.

  7. Perhaps you're making it harder than it needs to be.

    If these images were on your server, you may elect to use a relative path, right?

    <img src="imgs/blah/some.png">

     

    So when your users enter an image as a full url, your aim is simply to make that the source,  no?

    <img src="http://notyourdomain.com/some.png">

    There isn't much to that.

     

    Now, if you want to cache local copies of those remote images, that's a better question.

    Is that what you meant?

    If so, look at file_get_contents( $url ) and be sure to check that it's really an image and not a malicious script.

  8. To my knowledge, there's no way to trace a function back to the script tag/src that loaded it. In fact, you don't even need the tag anymore.

     

    I've done this in an 'include' script, that does two things.

    - loads a script

    - removes it right away.

     

    Once parsed, the contents reside somewhere in the browser's magic brain, which varies by vendor.

     

    Capturing click events isn't very hard, but be aware of capture vs bubble:

    http://www.quirksmode.org/js/events_advanced.html

     

    I'd probably start a new thread for that

  9. greasemonkey loads last, so you can count on your loaded javascripts to be there. GM handles events a little different, as you're dealing with wrappers rather than the elements themselves.

     

    One trick that I've found is to use setTimeout to execute the function that do your business; the scope there should be the real window.

     

    setTimeout(function(){ document.getElementById('foo').onclick=function(){} }, 20);

     

    If your GM script tried to do something "illegal", it stops silently. I like to console.log (firebug) every few lines to be sure that the whole script is executed.

  10. Mozilla supports fn.toSource() ,  and both Mozailla and IE support fn.toString();

     

    With these, you can override existing functions;

     

    elm.oldclick = elm.onclick;
    elm.onclick = function()
    {
         eval( this.oldclick.toString().replace(/black/g,'white') );
    };
    

     

    something like that.

  11. "submit" may not be a function, but is it an object?

     

    alert( typeof document.forms[frmName].submit );

     

    If it is, then you've probably fallen for an old trick,  naming the submit button "submit"

     

    <input type="submit" name="submit" value="submit"/>

      ...  don't do this!

    It overrides the native submit method with a reference to the form element.

     

    ---

    RE:

    var phoneElementName  = document.forms[frmName].elements[fieldPhone].name;

     

    Doesn't phoneElementName == fieldPhone  ?  That seems strange to me.

  12. The validation error is probably because of the tags in the script:

      prev: '<span>Prev</span>'

     

    I'd imagine you'd get the same thing from

      prev: $("<span/>").html("Prev")

     

    You may want to try createElement, just to get the tag characters out of the way:

     

    $("#plant").fdplant({

          prev: (function(e){ e.innerHTML="Prev"; return e;})(document.createElement('span'))

          next: (function(e){ e.innerHTML="Next"; return e;})(document.createElement('span'))

      });

    });

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.