You are here: Re: who is good at regular expressions? « PHP Programming Language « IT news, forums, messages
Re: who is good at regular expressions?

Posted by Erwin Moller on 09/07/05 15:27

brendan wrote:

> my regular expression knowledge is admittedly amateurish ... I have spent
> an hour trying to get this to work without any great success, but am in
> the middle of a big project so I can't waste a day fiddling around to get
> it to work (although I might have to if someone here can't help).
>
> I thought I would throw it out to the group to see if anyone could solve
> the problem quick and easy.
>
> I need to break a search string into components to search against a
> database.
> We want to allow the user to specify database columns by using
>
> [column name][colon][search text]
>
> i.e.
> "author:Jane Smith institution:university of Cambridge year:1976"
>
> so basically we have to split the string at the beginning of any word that
> ends in a colon.
> I need then get an array with column_name=>column_value to construct a SQL
> query from.
>
> At the moment I'm just getting garbage or parse errors ... Can anyone
> help? Accolades for anyone that can. A pint of lager for anyone in
> Cambridge that can!
> cheers
> Brendan.


Hi,

Who needs regexp? :P

Try something like this:

<?
// [column name][colon][search text]

$test = "author:Jane Smith institution:university of Cambridge year:1976";
$result = array();

$parts = explode(":",$test);
for($i=0;$i<count($parts);$i+=2){
$result[$parts[$i]] = $parts[$i+1];
}

echo "<pre>".var_dump($result)."</pre>";
?>


Regards,
Erwin Moller

PS: Does your reward also include the ticket to Cambridge from Holland? ;-)

 

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

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