You are here: Re: preg_match/replace to fix a search query « PHP Programming Language « IT news, forums, messages
Re: preg_match/replace to fix a search query

Posted by fienen@gmail.com on 03/20/07 16:36

Thanks for all the input. My solution ended up somewhat different,
but in the same vein.

Another script handed off the data based on a regex trigger, therefore
I knew if this was invoked, it had to be a valid ISBN number, so no
need to actually test if it matched since I know it does. If the
query started with "ISBN" or "ISBN:", regardless of the number the
total length would be > 13, which is the longest the input could be
and be a valid ISBN, so I used:

if (strlen($bookISBN) > 13)
{
$bookISBN = preg_replace('/(\w+)(:)? (\d=)/', '$3', $bookISBN);
}

So far, so good. Everything works just as it should now.

On Mar 16, 1:15 pm, Sjoerd <sjoerd-n...@linuxonly.nl> wrote:
> fie...@gmail.com wrote:
> > if (preg_match("isbn:?%20", $value))
> > ...
> > Doesn't seem to work though. Any thoughts?
>
> - The pattern of preg_match needs delimiters. Mostly slashes are used
> for this: /pattern/
> - Each statement should be ended with a semicolon;
> - Note that PHP automatically URL-decodes the GET parameters, so %20 in
> the URL will become a space in the GET variable.
> - You can use the matches parameter to retrieve the ISBN number.
> - When asking a question here, "doesn't seem to work" is not good
> enough. Insert echo statements to see whether the preg_match actually
> matches and report any error you get in your post.
>
> if (preg_match("/isbn:? ([0-9X]*)/", $value, $match))
> {
> $isbn = $match[1];}
>
> else
> {
> $isbn = $value;
>
> }
>
> Sjoerd

 

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

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