...

View Full Version : Please help: function to prevent numbers and @ signs in text field



mark-new
03-03-2012, 07:01 PM
I have this code on the submit.php file, but I am getting a syntax error.

function check_fields()
{

$HTTP_POST_VARS['brief']=preg_replace("/0,1,2,3,4,5,6,7,8,9/", /www/",/@/",""$HTTP_POST_VARS['brief']);

}

Please help. I need to delete or remove phone numbers, web address and email from the brief field. Many thanks

litebearer
03-03-2012, 07:23 PM
http://php.net/manual/en/function.str-replace.php
http://php.net/manual/en/function.preg-replace.php

mark-new
03-03-2012, 09:08 PM
I have this code on the submit.php file, but I am getting a syntax error.

function check_fields()
{

$HTTP_POST_VARS['brief']=preg_replace("/0,1,2,3,4,5,6,7,8,9/", /www/",/@/",""$HTTP_POST_VARS['brief']);

}

Please help. I need to delete or remove phone numbers, web address and email from the brief field. Many thanks

litebearer
03-03-2012, 10:53 PM
As a start; HTTP_POST_VARS is deprecated, you should be using $_POST.

Secondly what if someone uses 'shorthand' and writes "I was @ the show"? Or "There were 3 of us"?

three params $pattern, $replacement, $string - Does your example have three?

mark-new
03-03-2012, 11:02 PM
As a start; HTTP_POST_VARS is deprecated, you should be using $_POST.

Secondly what if someone uses 'shorthand' and writes "I was @ the show"? Or "There were 3 of us"?

three params $pattern, $replacement, $string - Does your example have three?

Thank you for your response. I am new to this, I just want to apply this rule. what is the correct code format . I already have a field for phone numbers and emails, I just do not want it in description field. Thanks

felgall
03-03-2012, 11:26 PM
For email addresses you could extract everything on either side of the @ out to the nearest word boundary ( /\b.+?@.+?\b/ ) and then use if(filter_var($email, FILTER_VALIDATE_EMAIL)) to determine if it is an email address and therefore needs to be removed. You should be able to do that test in about a dozen lines of code.

Unfortunately while email addresses have a standard format, phone numbers so not and since they can contain spaces and even letters there is not actuall boundary that you can easily use to perform a similar test for phone numbers. The amount of code needed to actually identify a phone number in a free format field is huge. I actually looked into that situation about 20 years ago where I needed to extract phone numbers from a free format field where most records did contain a phone number. With the several hundred lines of code that I settled on using for trying to identify phone numbers I still had about 5% of the results where dates or other numbers had been matched instead of actual phone numbers.

mark-new
03-03-2012, 11:38 PM
For email addresses you could extract everything on either side of the @ out to the nearest word boundary ( /\b.+?@.+?\b/ ) and then use if(filter_var($email, FILTER_VALIDATE_EMAIL)) to determine if it is an email address and therefore needs to be removed. You should be able to do that test in about a dozen lines of code.

Unfortunately while email addresses have a standard format, phone numbers so not and since they can contain spaces and even letters there is not actuall boundary that you can easily use to perform a similar test for phone numbers. The amount of code needed to actually identify a phone number in a free format field is huge. I actually looked into that situation about 20 years ago where I needed to extract phone numbers from a free format field where most records did contain a phone number. With the several hundred lines of code that I settled on using for trying to identify phone numbers I still had about 5% of the results where dates or other numbers had been matched instead of actual phone numbers.

Thanks, I only wanted to remove numeric numbers not necessarily phone numbers. ok let say I do not want to filter the numeric numbers and want remove or replace the @signs and web url how would the correct syntax for this code be implemented?

function check_fields()
{

$HTTP_POST_VARS['brief']=preg_replace("/0,1,2,3,4,5,6,7,8,9/", /www/",/@/",""$HTTP_POST_VARS['brief']);

}

Thanks for your help

felgall
03-04-2012, 12:07 AM
$brief = preg_replace("/\d|@/","",$_POST['brief']);

will get rid of all the numbers and @ symbols in the text. (note that $HTTP_POST_VARS is a PHP 3 command that was replaced by $_POST in PHP 4).

mark-new
03-04-2012, 12:56 AM
$brief = preg_replace("/\d|@/","",$_POST['brief']);

will get rid of all the numbers and @ symbols in the text. (note that $HTTP_POST_VARS is a PHP 3 command that was replaced by $_POST in PHP 4).

Many thanks it works, my application is using PHP3. Many thanks again

felgall
03-04-2012, 01:18 AM
Why are you using PHP 3 - PHP 4 is long dead and full of security holes - PHP 3 is positively pre-historic and should never be even remotely considered unless you are living in the stone age or earlier.

mark-new
03-04-2012, 02:19 AM
I do not know if this make sense, I am using jooomla 1.5 with php 5.2.17 but the php file I am working on uses $HTTP_POST_VARS in the coding.

felgall
03-04-2012, 08:13 AM
I do not know if this make sense, I am using jooomla 1.5 with php 5.2.17 but the php file I am working on uses $HTTP_POST_VARS in the coding.

Why are you running such an antiquated version of Joomla? The latest security patch is 2.5.1.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum