Re: Re: pattern containing single quote in IF statement

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

 



First of all, I strongly feel that you should have double quotes around the string you like to compare with (e.g. "new"). Otherwise, you are comparing against a string but to something else (integer ?). Without quotes, PHP will throw an error (not sure if it will throw a fatal error or something else). Second, do a var_dump on $_GET ['query']. What do you get? (white space before, after the string? encodes quotes?) You may also look at the function strcasecmp, which is little more elegant than your solution, in my opinion.

Regarding your question about "multiple OR", I would do something like:

$things_to_look_for = array ( "new, "newday" ... and so on);
if ( in_array ( $_GET['query'], $things_to_look_for ) ) {
	// do some stuff
}

/frank

26 dec 2006 kl. 14.42 skrev Jahangir:

I tried that also but it didnt work.
if($_GET['query']=="some'u'all")
{ filter($query);}
I still get the same error.

""Jahangir"" <jahan9@xxxxxxxxx> wrote in message
news:38.50.35414.C3021954@xxxxxxxxxxxxxxx
I am stuck at a wierd problem. I am trying to do comparision between a
"query string" and a "string value". the string consists of some
diacriticals and single quotes.
But when i try to escape the single quotes using backshash (\) it doesnt work. and when i try to use it inside a double quote preg_replace () doesnt
recognise the code.
why is php not comaparing string with single quotes??

here is the code:
 if($_GET['query']==new)
 { filter($query);}
 elseif($_GET['query']==some'u'all)
 { filter($query);}
 elseif($_GET['query']==all'u'ppl)
 { filter($query);}

 function filter($query)
 {
 $pattern = array ('/new/','/some'u'all/','/all'u'ppl/');
 $rep = array ("new way","Some of you all ","all of you");
 $op = preg_replace($pattern,$rep,$_GET['query']);
 echo "<br>new value $op";
}


also i wanted to just clarify is there a way of using multiple OR's in the
same "if" condition
i.e if(($_GET['query]')==new||newday||newtime||newbeginning|| newthing)
{
// fn here;
}

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


--
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