I have little experience with PHP and regular expressions. I created a simple html input form and a submit button. i would like to do the following:
When the button is clicked, regexp splits the input string into an array of words:
- that are all lowercase (with all ã changed to a)
- and are all 10 symbols long.
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:
<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>
Answer:
Maybe it is because your form method is POST but you are looking at $_GET?
$search_string = $_POST['keywords'];
No comments:
Post a Comment