0

Hello all,

I am trying to use more regex but I can't seem to get this to work. The aim is to check inputs for either [url, [link or <a href:

$islink = false;

 foreach($_POST as $k => $v){
	 if((preg_match("/[url|[link|<a href/i", $v)) > 0 ){
	 	$islink = true;
	 }
 }

 #gather data in sanitised variables
 $name 		= make_safe($_POST['name']);
 $feedback 	= make_safe($_POST['feedback']);
 $refer 	= make_safe($_POST['refer']);

 if($name && $feedback && !$islink){//process}

The if keeps executing, Any help would be great

3
Contributors
3
Replies
5
Views
6 Years
Discussion Span
Last Post by liamfriel
0
<?php
$subject = "<a href='google.com'>Google link</a>";
$pattern = "/url|link|href/";

preg_match($pattern, substr($subject,3), $matches, PREG_OFFSET_CAPTURE);
print_r($matches);
?>
1

You need to escape the bracket, because it is a reserved char in a regex.

preg_match("/\[url|\[link|<a href/i", $v)
Votes + Comments
Solved my problem quickly and efficiently thanks
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.