You are here: Re: pattern containing single quote in IF statement « PHP Programming Language « IT news, forums, messages
Re: pattern containing single quote in IF statement

Posted by BKDotCom on 12/26/06 17:39

thecoolone wrote:
> here is the code:
> if($_GET['query']==new)

is new a constant?! PHP will certainly think so. Put quotes around
your strings!
if( $_GET['query'] == 'new' )

> { filter($query);}
> elseif($_GET['query']==some'u'all)

// same problem here. I'm sure your error-log is full of run-time
errors. There's no way this script compiled.
elseif( $_GET['query' ]== 'some\'u\'all' )

> { filter($query);}
> elseif($_GET['query']==all'u'ppl)

same problem


> { filter($query);}
>
> function filter($query)
> {
> $pattern = array ('/new/','/some'u'all/','/all'u'ppl/');

escape your quotes
$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']);

why are you using regular expressions? Just use str_replace


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

well, you can do this:
if (
in_array($_GET['query'],array('new','newday','newtime','newbeginning','newthing'))
)
{
}

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация