[英]splitting input words into an array
我對 PHP 和正則表達式的經驗很少。 我創建了一個簡單的 html 輸入表單和一個提交按鈕。 我想做以下事情:
單擊按鈕時,regexp 將輸入字符串拆分為單詞數組:
都是小寫的(所有 ã 都改為 a)
並且都是 10 個符號長。
應該是這樣嗎?
$search_string = $_GET['keywords'];
$regexp = preg_split(^[a-zA-Z]{1,10}+$, $search_string);
$regexp = strtolower($search_string);
這是我的簡單 html 代碼:
<div>
<label for="keywords">keywords:</label>
<input type="text" name="keywords">
</div>
<input type="submit" value="Add Records">
你能幫我改進我的正則表達式代碼嗎? 它似乎不起作用。
這是我的代碼:
<!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.