You are here: Re: What is wrong in this code? « PHP Programming Language « IT news, forums, messages
Re: What is wrong in this code?

Posted by Kimmo Laine on 10/19/06 10:50

"iulian.ilea" <iulian.ilea@gmail.com> wrote in message
news:1161253158.193150.10120@h48g2000cwc.googlegroups.com...
> <?php
> $string = "Copia (3) di Copia (99) di unita";
> $val = "Copia (99) di unita";
> if (eregi("Copia \(+[0-9]+\) di ".$val,$string))

The pattern here is
"Copia \(+[0-9]+\) di Copia (99) di unita"
the problem is the unescaped parenthesis. simple parenthesis have a special
meaning in regular expressions, they indicate a subpattern. It should be
"Copia \([0-9]+\) di Copia \(99\) di unita", ie. $val should be "Copia
\(99\) di unita".

> $vara = explode("Copia (",$string);
> $vara = explode(")",$vara[1]);
> var_dump($vara);
> $maxim = $vara[0];

This could be done easier using the subpatterns you've accidently
discovered. Like:

if(preg_match("#Copia \(([0-9]+)\) di Copia \(99\) di unita#", $string,
$matches))
$maxim = $matches[1];


--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti pδivittyvδ nettisarjis
spam@outolempi.net | rot13(xvzzb@bhgbyrzcv.arg)

 

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

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация