【发布时间】:2014-04-29 21:11:14
【问题描述】:
我有一个表格,其中将插入带有网址的文本。而且我已经有正则表达式验证规则来搜索网址。此规则将替换指向另一个文本的 Web 链接。但我的任务是编写一个函数来将所有这些地址保存到数组中。我怎样才能将所有这些地址保存到数组中?
这是我现在拥有的代码:
<html>
<head>
<meta charset="UTF-8">
<title>Expressions: Find web address in text</title>
</head>
<body>
<?php
/*--------Functions---------*/
function webCheck($webtext){
global $web_check;
$web_check = "/((http:\/\/www\.)|(http:\/\/)|(www\.))([a-z0-9]+([a-z0-9-]*[a-z0-9]+)*\.)+[a-z]+/i";
return preg_replace($web_check, "<b>was weblink here</b>", $webtext);
}
/*--------End of Functions----------*/
if(isset($_POST["webadd"])){
$webtext = $_POST["webtext"];
if (!empty($webtext)){
echo webCheck($webtext);
}else{
echo "Feald cannot be empty. Please enter some text.";
}
} else {
echo "Please enter text in text area.";
}
?>
<form action="expression3.php" method="POST">
<table>
<tr>
<td>Find web address in text</td>
</tr>
<tr>
<td> <textarea name="webtext" cols="50" rows="10"></textarea></td>
</tr>
<tr>
<td><input type="submit" name="webadd" value="Find Web Address!" /></td>
</tr>
</table>
</form>
</body>
【问题讨论】: