0

自分のウェブサイトですばやく検索したい。値が入力され、好みのキーワードと一致すると、そのページにリダイレクトされます。

これまでのところ、これは私が得たものです:

<form method="get" action="redirect.php" > 
<input id="search" name="search" type="text" value="Search Here" />
<input name="submit" type="submit" value="Go" />
</form>


<?php

 if(isset($_GET['submit']));

 $product1_keywords = array('animal feeds', 'weanrite', 'Wean Rite');
 // my preffered keywords


 $search = $_GET['search'];
 // caller of entered value on text field  ???


if ($search = $product1_keywords) {
// if value of text field is matched with my preferred keywords


    // Redirect page if match
header('Location: http://localhost/equalivet_2/#products/wean_rite.html');
}

else {

// Redirect page if not match
header('Location: http://localhost/equalivet_2/not_found.html');
}

    ?>

お願い助けて。ありがとうございました。

4

7 に答える 7

2

あなたが探しているのはin_array、次のように使用するものだと思います:

<?php

if(isset($_GET['submit']));

$product1_keywords = array('animal feeds', 'weanrite', 'Wean Rite');
// my preferred keywords

$search = $_GET['search']; 
// caller of entered value on text field  ???

if(in_array($search , $product1_keywords)) {

  // if value of text field is matched with my preferred keywords

  // Redirect page if match
  header('Location: http://localhost/equalivet_2/#products/wean_rite.html');

} else {

  // Redirect page if not match
  header('Location: http://localhost/equalivet_2/not_found.html');

}

?>
于 2012-09-28T05:01:12.103 に答える
0

みんな、ありがとう。

複数の製品がある場合は、ソリューションを追加します。

 <?php

 if(isset($_GET['submit']));


 $product1_keywords = array('feeds', 'weanrite', 'Wean Rite');

 $product2_keywords = array('gro rite', 'Gro Rite', 'grorite', 'growing feeds');

 $product3_keywords = array('rite start', 'Rite Start', 'starter feed');



 $search = $_GET['search']; 
  // caller of entered value on text field  ???


  if(in_array($search , $product1_keywords)) {

    // if value of text field is matched with my preferred keywords

    // Redirect page if match
   header('Location: http://localhost/equalivet_2/#products/wean_rite.html');

  } 

  elseif(in_array($search , $product2_keywords)) {

  header('Location: http://localhost/equalivet_2/#products/gro_rite.html');

  }
  elseif(in_array($search , $product3_keywords)) {

  header('Location: http://localhost/equalivet_2/#products/rite_start.html');

  }



  else {

 // Redirect page if not match
  header('Location: http://localhost/equalivet_2/equalivet/not_found.html');

  }

  die;
  ?>

ありがとうございました。そして、これがこの投稿を必要とする人々の助けになることを願っています

于 2012-09-29T05:16:12.997 に答える
0

php の in_array 関数を使用できます。このリンクを見てください http://php.net/manual/en/function.in-array.php

于 2012-09-28T05:02:15.793 に答える
0

関数を使用して、in_array()提供された入力が指定したキーワードのリストと一致するかどうかを検索する必要があります。

in_array — 値が配列に存在するかどうかを確認します

于 2012-09-28T05:02:45.960 に答える
0

in_array検索テキストで確認する必要があります

<?php

 if(isset($_GET['submit']));

 $product1_keywords = array('animal feeds', 'weanrite', 'Wean Rite');
 // my preffered keywords


 $search = $_GET['search'];
 // caller of entered value on text field  ???


if(in_array($search , $product1_keywords)) {
// if value of text field is matched with my preferred keywords


    // Redirect page if match
header('Location: http://localhost/equalivet_2/#products/wean_rite.html');
}

else {

// Redirect page if not match
header('Location: http://localhost/equalivet_2/not_found.html');
}

    ?>
于 2012-09-28T05:02:48.937 に答える
0

この行にロジックの問題があります:

if ($search = $product1_keywords) {

==の代わりにする必要があり=ます。ただし、これはあなたの質問には答えません。

私の理解が正しければ、ユーザーが入力したキーワードに基づいてユーザーをリダイレクトしたいだけです。ユーザーをオールインワンにリダイレクトするキーワードと URL を含むように、キーワード配列を更新することをお勧めします。

$product1_keywords = array(
    'animal feeds' => '/url1',
    'weanrite' => '/url2',
    'wean rite' => '/url3'
);

次に、これをループして、入力されたキーワードを確認します (大文字と小文字の区別は無視します)。

$search = strtolower($_GET['search']);
foreach ($product1_keywords as $keyword => $url) {
    if ($search == $keyword) {
        // we found a keyword match!
        header($url);
        die();
    }
}
// if it makes it here, they didn't match a keyword
header('/not-found.html');
die();

すべてのキーワードが同じ URL にある場合は、$product1_keywords配列内のすべてのキーワードを同じ URL に設定する、 PHP のin_array()メソッドを使用して検索を高速化できます。

$search = strtolower($_GET['search']);
$url = in_array($search, $product1_keywords) ? '/url-found' : '/not-found.html';
header($url);
die();
于 2012-09-28T05:03:26.447 に答える
0

次のコードを使用できます。

<?php
$test1 = "hi";
$test2 = array("hi","hello");

for($i = 0; $i<sizeof($test2);$i++)
{
similar_text($test1, $test2[$i], $percent); 
    if($percent==100)
        echo "Match found";
}

?>

于 2012-09-28T05:20:20.990 に答える