正则表达式判断email和URL, 帮忙看看有没有要补充的.
类别: PHP教程
<body onload="f.a.select();">
<?php
echo 'a:'.htmlspecialchars($a);
echo '<br>a1:';
$a1 = eregi_replace('(^[_.][:alnum:]-]+@([[:alnum:]][[:alnum:]-]*.)+[[:alpha:]]{2,3}$)',' <a href="mailto:/1">/1</a> ', $a) ;
echo htmlspecialchars($a1);
echo "<br>a1:$a1";
echo '<br>a2:';
$a2 = eregi_replace('([[:alnum:]]+://([[:alnum:]][[:alnum:]-]*/.)+[[:alpha:]]{2,3}([#/?///][^#/?///][:space:]][^[:space:]]*)?)',
'<a href="/1" target="_blank">/1</a>', $a);
echo htmlspecialchars($a2);
echo "<br>a2:$a2";
// eregi('^[_.][:alnum:]-]+@([[:alnum:]][[:alnum:]-]*/.)+[[:alpha:]]{2,3}$',$a) or die("not a email");
?>
<form name="f">
<input name="a" value="<?php echo $a; ?>">
<input type="submit" >
</form>
</body>
<?php
echo 'a:'.htmlspecialchars($a);
echo '<br>a1:';
$a1 = eregi_replace('(^[_.][:alnum:]-]+@([[:alnum:]][[:alnum:]-]*.)+[[:alpha:]]{2,3}$)',' <a href="mailto:/1">/1</a> ', $a) ;
echo htmlspecialchars($a1);
echo "<br>a1:$a1";
echo '<br>a2:';
$a2 = eregi_replace('([[:alnum:]]+://([[:alnum:]][[:alnum:]-]*/.)+[[:alpha:]]{2,3}([#/?///][^#/?///][:space:]][^[:space:]]*)?)',
'<a href="/1" target="_blank">/1</a>', $a);
echo htmlspecialchars($a2);
echo "<br>a2:$a2";
// eregi('^[_.][:alnum:]-]+@([[:alnum:]][[:alnum:]-]*/.)+[[:alpha:]]{2,3}$',$a) or die("not a email");
?>
<form name="f">
<input name="a" value="<?php echo $a; ?>">
<input type="submit" >
</form>
</body>
-= 资 源 教 程 =-
文 章 搜 索