[英]splitting input words into an array
I have little experience with PHP and regular expressions.我对 PHP 和正则表达式的经验很少。 I created a simple html input form and a submit button.我创建了一个简单的 html 输入表单和一个提交按钮。 i would like to do the following:我想做以下事情:
When the button is clicked, regexp splits the input string into an array of words:单击按钮时,regexp 将输入字符串拆分为单词数组:
that are all lowercase (with all ã changed to a)都是小写的(所有 ã 都改为 a)
and are all 10 symbols long.并且都是 10 个符号长。
Should it be like that?应该是这样吗?
$search_string = $_GET['keywords'];
$regexp = preg_split(^[a-zA-Z]{1,10}+$, $search_string);
$regexp = strtolower($search_string);
This is my simple html code:这是我的简单 html 代码:
<div>
<label for="keywords">keywords:</label>
<input type="text" name="keywords">
</div>
<input type="submit" value="Add Records">
Can you help me improve my regexp code?你能帮我改进我的正则表达式代码吗? It doesn't seem to be working.它似乎不起作用。
This is my code:这是我的代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<form action="htmlform.php" method="POST">
keywords <input type="text" name="keywords">
<input type="submit" value="submit">
</form>
<?php
$search_string = $_GET['keywords'];
$regexp = preg_split("/^[a-zA-Z]{1,10}+$/", $search_string);
$regexp = strtolower($search_string);
?>
</body>
</html>
也许是因为您的表单方法是 POST 但您正在查看 $_GET?
$search_string = $_POST['keywords'];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.