0

URLのスクリプトタグを確認したい

例: URL に script タグがある場合、以下のシナリオは正常に機能しています。

<?php
 $url = 'admin/content/test/<script>';
 preg_match('<script>', $url, $match);
 if (count($match) >= 1) {
  print 'It executes';
 }
?>

出力: It executes

しかし、私の場合、URLに文字列「product_description」がある場合、上記の条件も一致します

<?php
  $url = 'admin/content/product_description/test';
  preg_match('<script>', $url, $match);
  if (count($match) >= 1) {
   print 'It executes';
  }
?>

出力: 実行します

URL のスクリプト タグを確認する正しい方法を提案してください。

4

2 に答える 2

1

strpos の代わりに使用してみてくださいpreg_match:

if (strpos($url,'<script>') !== false) {
   print 'It executes';
}

ここに、この機能のマニュアルがあります: documentation

于 2013-06-27T11:35:34.470 に答える