Reply to Re: problem with if (ereg)

Your name:

Reply:


Posted by Dan on 10/08/05 17:57

If you really need to use regular expressions then you could try something
like this:

if (ereg("^0030697$", $myquery_called_number)) {
$myquery_called_number = 'general';
}elseif (ereg("^0030697111", $myquery_called_number)) {
....
} elseif (ereg("^0030697211", $myquery_called_number)) {
....
....
}

The first IF tests for 'starts with and ends with'. ELSEIFs test for 'starts
with' only.

Still, regular expressions are simply an overkil here. I'd suggest you use
strcmp() and strncmp() functions. The first one compares whole strings
while the other one compares n number of characters from each string. So
your code might look something like this:

if (0 == strcmp($myquery_called_number, '0030697')) {
$myquery_called_number = 'general';
} elseif (0 == strncmp($myquery_called_number, '0030697111', 11)) {
$myquery_called_number = 'low';
} elseif ( etc....


Hope this help.
Bogdan



"fender_gr" <pfender@gmail.com> wrote in message
news:1128682156.261080.59600@o13g2000cwo.googlegroups.com...
> Dear All,
>
>
> How can i convert the following numbers (row1) to text (row2)
>
> 0030697 --> general
> 0030697111xxxx --> low
> 0030697211xxxx --> medium
> 0030697011xxxx --> high
>
> I have tried the following but always matches the numbers accodring to
> the first if case :
>
> if (ereg("0030697", $myquery_called_number)) {
> $myquery_called_number='GENERAL'; } else { $myquery_called_number =
> "$myquery_called_
> number";}
>
> if (ereg("0030697111xxxx", $myquery_called_number)) {
> $myquery_called_number='LOW'; } else { $myquery_called_number =
> "$myquery
> _called_number";}
>
> if (ereg("0030697211xxxx", $myquery_called_number)) {
> $myquery_called_number='MEDIUM'; } else { $myquery_called_number =
> "$myquery
> _called_number";}
>
> if (ereg("0030697011xxxx", $myquery_called_number)) {
> $myquery_called_number='HIGH'; } else { $myquery_called_number =
> "$myquery
> _called_number";}
>
> the output for this is :
>
> GENERAL
> GENERAL
> GENERAL
> GENERAL
>
> but i was expected to see
>
> GENERAL
> LOW
> MEDIUM
> HIGH
>
> any ideas ?
>
> Thanx
>

[Back to original 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

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