Thread: searching array
View Single Post
Old 05-03-2009, 02:18 PM   #5 (permalink)
allworknoplay
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by Enfernikus View Post


This'll output what you want, how ever for future references some pointers.

when using echo to output data please the comma instead of the period to concatenate strings it is faster.

when you're processing strings without variables in them use single quotes as PHP doesn't process them.

Unless I'm mistaken standards mandate html be lowercase so <BR /> should <br />

P.S - I am not sure this would be the best method.
Thanks, I had no idea that you can use commas to concatenate strings!? Of all the operators I've been reading about they have never mentioned comma as a concatenater!!!

I guess I got the HTML mandate backwards, I thought it was all capitals....

Thanks for the code.....


Quote:
Originally Posted by Kalle View Post
You are using in_array incorrectly in the second sample code; You are iterating over a block of elements and pass the second parameter to in_array() as a string where it would expect an array, further though the first parameter for in_array() does not work as a wildcard, it will see if theres an element with that content in this case ISBN and nothing else, meaning it will always return false here.

What you need to do is to use something like str[i]str():
PHP Code:
...
if(
stristr($id'ISBN') !== false)
{
    ...
}
... 
Ohhh I was close. I did try strstr but didn't mention it because I thought I was way off....never tried stristr though.....



Quote:
Originally Posted by Salathe View Post
If you want to go the regular expression route, there's another function which is much friendlier to arrays: preg_grep.

Example
PHP Code:
$test  = array('Wfjheighe','ISBN:454656','ISBN:9090943');
$isbns preg_grep('/^ISBN:\d+$/Di'$test);
print_r($isbns); 
Output
Code:
Array
(
    [1] => ISBN:454656
    [2] => ISBN:9090943
)
I'll take a look at your code as well, I need to get better at Regex....

As always thanks!
allworknoplay is offline  
Reply With Quote