Jump to content


Photo

Preg_match issue


  • Please log in to reply
3 replies to this topic

#1 hotaru

hotaru
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 07 April 2006 - 04:34 AM

Here's the basic preg_match:

$pattern = '/^[a-z0-9]*$/i';
if (!preg_match($pattern, trim($_GET["p"])) || strlen(trim($_GET["p"]) == 0))

Now if I have a p that equals a number, it shows the data, but it the p contains letters, it doesn't work! Can someone help, please?

#2 DougieB2

DougieB2
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 07 April 2006 - 08:04 AM

seems to work ok. can you give an example of a 'p' string that fails?

#3 hotaru

hotaru
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 07 April 2006 - 11:36 AM

./p=icons

#4 DougieB2

DougieB2
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 07 April 2006 - 08:03 PM

[a href=\"http://localhost/test.php?p=icons\" target=\"_blank\"]http://localhost/test.php?p=icons[/a]

works for me.

test.php:
<?php 
$pattern = '/^[a-z0-9]*$/i';
if (!preg_match($pattern, trim($_GET["p"])) || strlen(trim($_GET["p"]) == 0))
{
echo "<html><body>fails</body></html>";
exit;
}
echo "<html><body>success</body></html>";
?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users