You are here: Re: ereg_replace « PHP Programming Language « IT news, forums, messages
Re: ereg_replace

Posted by Bob Bedford on 07/05/06 15:57

"Krustov" <me@privacy.net> a ιcrit dans le message de news:
MPG.1f15e57e76d40b9989b4f@news.newsreader.com...
> <comp.lang.php>
> <Bob Bedford>
> <Wed, 5 Jul 2006 16:38:56 +0200>
> <44abcefc$0$12618$5402220f@news.sunrise.ch>
>
>> I need help: I've a string that is used to write down a phone number that
>> comes from a form and would like to keep it as clean as possible. For
>> avoiding people to create twice an account using a different syntax.
>>
>> For this the only char I'd like to allow are number 0-9, '/','.' and
>> spaces.
>>
>> I'd like to replace everything other by a "space".
>>
>> Lets give some examples:
>>
>> some allowed:
>> 555/55.55.55
>> 555 55 55 55
>> 555.555 555
>>
>> some not allowed and their changes:
>> 555-55-55-55 -> 555.55.55.55
>> 555,55,55,55 -> 555.55.55.55
>> 555:55;55_55 -> 555.55.55.55
>> 55555\55>55 -> 55555.55.55
>> and so on.
>>
>> How can I do that ? I'm not confortable with ereg_replace, so if you
>> could
>> give the final statement it would be greately appreciated.
>>
>
> The following is a cut-n-paste from another newsgroup .....
>
>> if (string_reject('ABCDEFGHIJKLMNOPQRSTUZWXYZabcdefghijklmnopqrstuvwxyz_
>> 0123',$skank)) {$pass=0;}
>>
>> Something simple like the above would be so much easier in some cases .
>>
>> Stuff like [^ makes it hard to understand .
>
> $checkthis="555:55;55_55";
> $ok="0123456789\.";
> string_reject($checkthis,$ok)
>
> function string_reject($mystring,$allowed)
> {
> return ereg("[^".$allowed."]",$mystring);
> }
>
> Perhaps sombody on here could alter/add the appropriate code to do what
> you require it to do .
>
>
> --
> Encrypted email address
> www.emailuser.co.uk/?name=KRUSTOV
>
thanks for your code: I've been able to do as simple as:
$number = ereg_replace("[^0-9/.]",".",$number);
(we decided to remove the "space" but may be easely be added I think).

Bob

 

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

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