The above works as expected. I bet you have magic_quotes_gpc ON. If you can turn them off, do it, otherwise, use stripslashes() before checking for hyperlinks.PHP Code:<?php
// I added this:
$_POST["message"] = 'My message is a link. <a href="http://www.something.com">Click here</a>';
// YOUR CODE BELOW:
if ($_POST["message"])
{
$message = $_POST['message'];
//check the message doesn't contain links
if (preg_match('/<a[\s]+[^>]*?href[\s]?=[\s\""\']+(.*?)[\""\']+.*?>([^<]+|.*?)?<\/a>/', $message))
{
echo 'there is a hyperlink';
}
else
{
echo 'No hyperlinks';
}
}
exit;
preg_match(), when used with the first two arguments only returns either 0 or 1. With that in mind, you can test the result of the evaluation with an if statment.
Good luck.
J



Reply With Quote

Bookmarks