Мой вариант:
| Код | <?php
$phone = "(1123) 123-1233"; print "Phone: " . ( ( preg_match( "#^\(\d{2,4}\)\s*\d{1,3}\-\d{2,4}$#" , $phone ) ) ? "Good" : "Bad" );
print "<br><br><br>";
$data = "jkhka 12.8 EU dsfns,. fjsfkl sfsnfsf 54 USD e656 56 56 23,6 RUR"; preg_match_all( "#\d+(?:(?:,|\.)\d)?+\s+(?:RUR|USD|EU)#s" , $data , $matches , PREG_PATTERN_ORDER ); print_r( $matches );
print "<br><br><br>";
$str = "ya.ru is the very good site, but not better that kgb.ru. test.su is opened. templ.com closed aeroflot.aero"; print preg_replace( "#([a-z0-9]{1,}(?:(?:[a-z0-9]{1,}[a-z0-9\-\.]{0,1}[a-z0-9]{1,})|[a-z0-9]{1,})*\.([a-z]{2,4}))#ei" , "test( '\\1' , '\\2' )" , $str ); function test( $f , $d ) { $d = strtolower( $d );
if( $d == "com" || $d == "net" || $d == "org" ) { return "<a href='http://" . $f . "'><span style='color:red;'>" .$f . "</span></a>"; }
if( $d == "ru" || $d == "su" || $d == "ua" ) { return "<a href='http://" . $f . "'><span style='color:blue;'>" .$f . "</span></a>"; }
if( $d == "aero" ) { return "<a href='http://" . $f . "'><span style='color:green;'>" .$f . "</span></a>"; }
return $f; }
print "<br><br><br>";
$email = "adsc...fsdfsd____f@ya.ma-test-il.ru"; print "Email: " . ( ( preg_match( "#^([a-z0-9]){1}[a-z0-9\-_.+]*([a-z0-9]){1}@[a-z0-9]{1,}(([a-z0-9]{1,}[a-z0-9\-\.]{0,1}[a-z0-9]{1,})|[a-z0-9]{1,})*\.[a-z]{2,4}$#i" , $email ) ) ? "Good" : "Bad" );
?> | Добавлено @ 16:16 Вариант PARROT ЗЫ: Сразу ставил параметры чтобы показать что не правильно.
| Код | <?php
#PARROT
$phone = "(112387593875894758937858937589733) 12456464563-124645-6464-6464-645-64633"; print "Phone: " . ( ( preg_match( "#^[\(\d\)]+[\s]*[\d-]+[\d]{2,4}$#" , $phone ) ) ? "Good" : "Bad" );
print "<br><br><br>";
$data = "jkhka 12.8 EU dsfns,. fjsfkl sfsnfsf 54 USD e656 56 56 .23. RUR"; preg_match_all( "#[\d.]+[\s]*(USD|RUR|EU)+#s" , $data , $matches , PREG_PATTERN_ORDER ); print_r( $matches );
print "<br><br><br>";
$str = "ya.ru is the very good site, but not better that kgb.ru. test.su is opened. templ.com closed aeroflot.aero"; print preg_replace( "#([\w-]*\.){1,2}[\w]{2,4}[?]?[[\w=&//]*]?#ei" , "test( '\\1' , '\\2' )" , $str ); function test( $f , $d ) { $d = strtolower( $d );
if( $d == "com" || $d == "net" || $d == "org" ) { return "<a href='http://" . $f . "'><span style='color:red;'>" .$f . "</span></a>"; }
if( $d == "ru" || $d == "su" || $d == "ua" ) { return "<a href='http://" . $f . "'><span style='color:blue;'>" .$f . "</span></a>"; }
if( $d == "aero" ) { return "<a href='http://" . $f . "'><span style='color:green;'>" .$f . "</span></a>"; }
return $f; }
print "<br><br><br>";
$email = "adsc...fsdfsd____f@ys_sa.ma-test-il.ru"; print "Email: " . ( ( preg_match( "#^(\w*(.|_|-))*@([\w-]*\.){1,2}[\w]{2,4}$#i" , $email ) ) ? "Good" : "Bad" );
?> | |