[PHP] php regexp question

2003-03-25 Thread cpaul



hi

i've made a small php site that is searching against french documents stored
in a mysql database.

when it comes to rendering search results, the client has asked if the words 
that were searched for can be highlighted.  

no problem! i thought.  just do a regexp replace and wrap a b tag around
the matching terms.  then i realised that the following would not produce
a match:

  $string = Françoise;
  echo preg_match(/francoise/i,$string);

so my question since mysql managed to produce a match here, is there
perhaps a php regexp modifier that (maybe) knows how to make this match?



thanks

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



Re: [PHP] test for associative or numerically indexed array

2003-03-20 Thread cpaul



 At 08:52 20.03.2003, cpaul said:
 [snip]
 ok thanks - that makes sense.  sort of doesn't solve my problem, because
 if my function receives an enumerated array, i want it to treat it as an
 associative array, using the value as the key.
 [snip] 


ernest wrote:

 What would be the value then?
 
 If I get you correctly, you would treat an array that comes like
 [0] = entry 0
 [1] = entry 1
 [2] = entry 2

like this:

  'entry 0' = 'entry 0'
  'entry 1' = 'entry 1'
  'entry 2' = 'entry 2'


 What happens when there are duplicate values in the source array? You will
 loose entries on duplicate values.

the source array is based on a directory listing, so i don't think there's
a possibility of that happening?



 You can't tell with absolute certainty if an array is enumerated, or built
 as associative array. Take this example:
 $a = array('one','two','three');
 $b = array(); $b[0] = 'one'; $b[1] = 'two'; $b[2] = 'three';
 $c = array(0 = 'one', 1 = 'two', 2 = 'three');
 
 Which one would you believe is enumerated, and which one is associative?

they'd all be enumerated, except perhaps $c -- but i've grown :) and now
understand that $c winds up being an enumerated array.. or is it?

in my code

 $q = mysql_query ( SELECT production_id, title FROM productions ORDER BY title; 
);
 $this-all_productions[] = ;
 while ( $row = mysql_fetch_array( $q ) ) {  
   $this-all_productions[$row[production_id]] = $row[title];
 }

the array is kept in order when i foreach the array - wouldn't they sort
themselves into 0,1,2,3,4,5,etc if my while loop was populating an 
enumerated array?   or are all arrays in php actually a keyed hash?



 What you can do is walk the array keys and check if there is at least a
 single non-numeric key. If you found one the array is associative. If you
 found none it may be likely that the array is enumerated, but you can't be
 sure in a general way, except your application is designed in a way that
 uses always non-numeric keys for associative arrays.

thanks so much for all your input on this.





regards



-- 
chris paul

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



Re: [PHP] test for associative or numerically indexed array

2003-03-20 Thread cpaul

 So much for the theory - what are you really trying to achieve? Maybe
 there's something you can redesign so you're not relying on the fact if an
 array is enumerated or not.

thanks very much for your help - i understand now that no matter what
kind of array i think i'm making, it is being morphed into an associative
array.  i half-understood this from the docs, but was puzzled.. i expected
the behaviour of an array in other languages, which even if i were to
define an array in this sequence:

$arr[2] = z;
$arr[0] = x;
$arr[1] = y;

would shuffle itself internally into a sequence like: x, y, z.

but in php this obviously isn't the case, and it remains: z, x, y.

thanks again for your time.




-- 
chris paul


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



[PHP] test for associative or numerically indexed array

2003-03-19 Thread cpaul


Is there a method to test whether or not an array is associative?

I'm trying to make a function that can deal with whatever type of
array (associative or numeric) that is thrown at it.

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



Re: [PHP] test for associative or numerically indexed array

2003-03-19 Thread cpaul

 --- cpaul [EMAIL PROTECTED] wrote:
  Is there a method to test whether or not an array is associative?


[EMAIL PROTECTED] wrote:

 It's all the same. An enumerated array is really an associative array where
 every key is an integer. Just treat them all like associative arrays, and
 you'll be fine.
 

ok thanks - that makes sense.  sort of doesn't solve my problem, because
if my function receives an enumerated array, i want it to treat it as an
associative array, using the value as the key.

the array index is not useful to me in this situation.

is there really no way to tell how an array was defined?


thanks for your time


-- 
chris paul

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