Jump to content

Possibly easy mistake: PREG_MATCH and WordList


Recommended Posts

<html><title>program6</title>

<body>

<form method="POST" action="

<?php echo $PHP_SELF;?>

">

<?php
echo "<select name=s>";
for ($count=65; $count<=90; $count++)
{
        echo "<option value=".chr($count).">".chr($count)."</option><br>";
}
echo "</select>";
?>

<?php
echo "<select name=t>";
for ($count=65; $count<=90; $count++)
{
        echo "<option value=".chr($count).">".chr($count)."</option><br>";
}
echo "</select>";
?>

<input type="submit"/>

</form>

<hr>

<?php
if (isset($s))
{
        $first=strtolower($_POST["s"]);
        $second=strtolower($_POST["t"]);
        echo "A word that starts with ".$first." and ends with ".$second." is: <br>";
        preg_match("/^$first.*%second/i", file('/words'), $words);
        echo $words[1];

}
?>

</body>

</html>

 

Ok, so what this program is doing is taking 2 letters (chosen by user from SELECT options) and then calling the php script to search through the 'word' file in the local directory for 3 words that begin with the first option and end with the second:

 

Basically:

 

if user chooses A and T...

OUTPUT: Adult, Agincourt, Ant

 

 

For some reason, I can't wrap my mind around why I can't get this to work, I'm assuming it's the regular expression or something, btw, this is my first day/project using PHP, so PLEASE explain this as if I were mildly slow

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.