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

Posted by xicheng on 07/05/06 16:05

Bob Bedford wrote:
> Hello there,
>
> 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".

a "space" or a "dot"??

> 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.

It looks to me that you want to replace all characters which are not a
number, a dot a space or a slash to "dot", is this true?? then you
might try:

$newstr = preg_replace("/[^\d.\/ ]+/", ".", $oldstr);

(untested)

I added a plus in the pattern /[^\d.\/ ]+/ to replace also something
like:

555:55;_@55_55 to 555.55.55.55 instead of 555.55...55.55

Xicheng

 

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

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