Page 1 of 1

About array_search and preg_match,why 1,2, is not output

Posted: Fri Aug 01, 2003 11:16 am
by saloufeng

Code: Select all

<?php
	$a = '11';
	$b = '11,';
	$c = explode(',', $b);
	echo $c;
	if(array_search($a,$c))&#123;
	  echo 1;
	&#125;
	if(preg_match("#$".$a.",#",$b))&#123;
	  echo 2;
	&#125; 
	if(preg_match("#".$a.",#",$b))&#123;
	  echo 3;
	&#125; 
?>
why 1,2, is not output?

Posted: Fri Aug 01, 2003 11:43 am
by nielsene
I'm not sure why array_search is acting up. I just tried in_array($a,$c) and that worked fine.

Your number two is broken because you are using an unescaped dollarsign in the doubly quote string. Either escape the dollar sign or change to single quotes.

Posted: Fri Aug 01, 2003 7:53 pm
by nielsene
On number 2, haven't you flipped your '$' and '^'? Isn't '^' beginning of string and '$' end of string? So of course it doesn't match as it is impossible to match something that specifies the end of string before the beginning of string.

Posted: Fri Aug 01, 2003 10:54 pm
by saloufeng
nielsene.
yea,I'm sorry,I made mistakes.
Thank you!