Jump to content

Help with removing emails, tel no and web url from a text field


php-newbies

Recommended Posts

Merry xmas and happy new in advance to you all.

 

I have a web form where user submit an ad. Everything is working just fine. However there is a field name brief. The brief field is where user add info about their ad. Now people are including web url, phone numbers and email address in this field which make the ad look like spam.

 

In the code there is already a function that check if they have entered their email address in the email field. I want to add a function to the check field to include the brief field. The function should either automatically delete any phone number/email addr/web url or replace with with my website name if detected in the brief field.

 

Your help will be highly appreciated.

<?php
function check_fields()
{
global $db_entry, $visible_val, $cat_fields, $email, 
$HTTP_POST_VARS, $photos_count, $phptomaxsize, $userfile, $prviewphotomax,
$incl_prevphoto, $incl_mtmdfile, $mtmdfile_maxs, $userfile_name, $select_text, $msg2;



if(!get_magic_quotes_gpc())
{

foreach ($HTTP_POST_VARS as $key5 => $value )
{
$HTTP_POST_VARS[$key5]=addslashes($HTTP_POST_VARS[$key5]);
}
}

foreach ( $cat_fields as $key => $value )
{
$HTTP_POST_VARS[$key]=ereg_replace('<', '&#060;', $HTTP_POST_VARS[$key]);
$HTTP_POST_VARS[$key]=ereg_replace('>', '&#062;', $HTTP_POST_VARS[$key]);

if ($cat_fields[$key][2]=="minmax")
{ $HTTP_POST_VARS[$key]=ereg_replace(',', '', $HTTP_POST_VARS[$key]); 

$HTTP_POST_VARS[$key]=preg_replace ('/[A-Za-z]|\$|,|\?|\+/', "", $HTTP_POST_VARS[$key]);

}

if ($cat_fields[$key][4]=="date")
{ 
$key_d=$key."_dd"; $key_m=$key."_mm"; $key_y=$key."_yy";
$HTTP_POST_VARS[$key]=$HTTP_POST_VARS[$key_y]."-".$HTTP_POST_VARS[$key_m]."-".$HTTP_POST_VARS[$key_d];

if (($HTTP_POST_VARS[$key_m] > 12)  or ($HTTP_POST_VARS[$key_m] < 1) or
($HTTP_POST_VARS[$key_d] > 31) or ($HTTP_POST_VARS[$key_d] < 1) 
or ($HTTP_POST_VARS[$key_y] < 1))
{
$message="
<center>
<font class='msgf2' >
  ".$msg2['incorr_date_f']."  ".$cat_fields[$key][0]."  </font>
</center>
"; 
output_mssg_ex($message);
return;
}


}

if ($cat_fields[$key][4]=="checkbox")
{
$aa5=split('<option>',$cat_fields[$key][7]);
$i_aa5=0;
foreach ($aa5 as $value1)
{
$i_aa5++;
$namechbx=$key.$i_aa5;
if ($HTTP_POST_VARS[$namechbx]!="")
{$HTTP_POST_VARS[$key]=$HTTP_POST_VARS[$key].$HTTP_POST_VARS[$namechbx]."; ";}
}
}


$str_length1=strlen($HTTP_POST_VARS[$key]);
$aa4=split(':',$cat_fields[$key][3]);
$fmaxsize=$aa4[1];
if ($aa4[2]!="") $fmaxsize=$aa4[2];

$fmaxsize=2*$fmaxsize;

if ( $str_length1 > $fmaxsize)
{
$message="
<center>
<font class='msgf2' >
  ".$msg2['Ad_info_in_field']." <font class='msgf1' >".$cat_fields[$key][0]." </font> ".$msg2['is_too_large_inf']."</font>
</center>
";
output_mssg_ex($message);
return;
}

if ($HTTP_POST_VARS[$key]==$select_text)
{$HTTP_POST_VARS[$key]="";}

if ($cat_fields[$key][5]=='1')
{
if (( $HTTP_POST_VARS[$key]=="") or ( $HTTP_POST_VARS[$key]=="http://"))
{
$message="
<center>
<font class='msgf2' >
  ".$msg2['Ad_field_c']." <font class='msgf1' > ".$cat_fields[$key][0]." </font> ".$msg2['was_mising_on_form']."</font>
</center>
";
output_mssg_ex($message);
return;
}
}
}
if ($cat_fields['email'][5]=='1'){
$HTTP_POST_VARS['email']=check_email($HTTP_POST_VARS['email']);
}

for ($i=1; $i<=$photos_count; $i++)
{
$i1=$i-1;
if (file_exists($userfile[$i1])){
if (filesize($userfile[$i1]) > $phptomaxsize)
{
$phptomaxsize1=$phptomaxsize/1000;
$message="
<center>
<font class='msgf2' >
  ".$msg2['Your_photo_n']." $i  ( ".$userfile_name[$i1]." )  ".$msg2['is_too_large_ph']." < $phptomaxsize1 
".$msg2['Kbyte_v'].".
</font></font>
</center>
";
output_mssg_ex($message);
return;
}
}
}

if ($incl_prevphoto=="yes")
{
$i1++;
if (file_exists($userfile[$i1])){
if (filesize($userfile[$i1]) > $prviewphotomax)
{
$prviewphotomax1=$prviewphotomax/1000;
$message="
<center>
<font class='msgf2' >
  ".$msg2['Your_preview_photo_d']." ( ".$userfile_name[$i1]." ) ".$msg2['is_too_large_prph']."
< $prviewphotomax1 ".$msg2['Kbyte_v'].".
</font></font>
</center>
";
output_mssg_ex($message);
return;
}
}
}
if ($incl_mtmdfile=="yes")
{
$i1++;
if (file_exists($userfile[$i1])){
if (filesize($userfile[$i1]) > $mtmdfile_maxs)
{
$mtmdfile_maxs1=$mtmdfile_maxs/1000;
$message="
<center>
<font class='msgf2' >
  ".$msg2['Your_multimedia_file']." ".$userfile_name[$i1]."
".$msg2['is_too_large_mmf']." < $mtmdfile_maxs1 ".$msg2['Kbyte_v'].".
</font></font>
</center>
";

output_mssg_ex($message);
return;
}
}
}


}

function checknusrads()
{
global $cat_fields, $table_ads, $ct, $page, $adsonpage,
$html_header, $html_footer, $usrads_chcktime, $usrads_max, $categories,$ch_nmusr,
$REMOTE_ADDR, $msg2, $msg, $templ, $indx_url; 

$timech1=time() - $usrads_chcktime*86400;
$sql_query="select count(idnum) from $table_ads where
ipaddr1='$REMOTE_ADDR' and time > $timech1";
$sql_res=mysql_query("$sql_query");
$row=mysql_fetch_row($sql_res);
$count=$row[0];

if ($count >= $usrads_max)
{
$message="
<font class='msgf2'>
<center> 
".$msg2['exceeded_max_n_ads']." ($usrads_max) ".$msg2['allowed_per_time_p']." ($usrads_chcktime ".$msg2['days_v']." 
<p>
<font class='stfnt'>
<a href='{$indx_url}md=browse&ipaddr1=$REMOTE_ADDR&visunvis=1'>".$msg2['Click_here_v']." </a>
".$msg2['to_see_your_ads']." 
</font>

</center>
</font>
";

$thtml= "
<center><table width='400'><tr><td>
<font class='stfntb'>
<b><a href='$indx_url'>".$msg['top'].":</a></b></font>
  
<font class='stfntb'> 
<b>  
<a href='{$indx_url}ct=$ct'>".$categories[$ct][0]."
</b></a> 
</font> 
<hr size='1'><p>
$message
<p><hr size='1'>
</tr></td></table>
</center>
";

include($templ['msg']);
return;
}
}

function check_duplication()
{
global $pradsdupl, $HTTP_POST_VARS, $table_ads, $msg2, $ct, $indx_url;



if ($pradsdupl=='yes'){

$email_d=$HTTP_POST_VARS['email'];
$title_d=$HTTP_POST_VARS['title'];

$dupl_k="0";

$time1=time() - 1000;
$sql_query="select idnum from $table_ads where title='$title_d' and  email='$email_d' 
and catname='$ct' and (time > $time1)";
$sql_res=mysql_query("$sql_query");
while ($row = mysql_fetch_array ($sql_res))
{
$dupl_id=$row['idnum']; $dupl_k="1";
}

if ($dupl_k=="1"){
global $moderating;
$title_d=stripslashes($title_d);
if ($moderating!="yes"){
$ttlad1="<a href='{$indx_url}md=details&ct=$ct&id=$dupl_id'>$title_d (ID# $dupl_id)</a>";
}
else {$ttlad1="<font color='#000077'>$title_d (ID# $dupl_id)</font>";}

$message="
<center>
<font FACE='ARIAL, HELVETICA' COLOR='#880000' >
<b> ".$msg2['tried_duplicate_ad']." <br>
$ttlad1
</font></b></font>
</center>
";

output_mssg_ex($message);
return;
}

}
}

function submit_ad()
{
global $db_entry, $visible_val, $cat_fields, $email, $HTTP_POST_VARS, $ch_nmusr,
$photo_url, $photo_path, $id_count, 
$userfile, $userfile_name, $visible_val, $html_header, $html_footer, $msg, $msg2, $paymgtw,
$photos_url, $photos_path, $photos_count, $moderating, $ad_idnum, $sndadmnotif,$use_spmg, $templ;

global $actadoptv; if($actadoptv=="yes"){$moderating="yes"; include_once("actlink.php");}

global $usevrfcode;
if ($usevrfcode=="yes"){include_once("vrfuncs.php"); if(!ch_vrcode()){return;}}

if($paymgtw=="yes"){include("ecmc.php"); check_pmsubmit();}

if ($ch_nmusr=="yes"){checknusrads();}

check_fields();

?>

 

 

 

Many thanks again

Link to comment
Share on other sites

  • 2 months later...

I have been struggling with this code but still having problem. Any help will be highly appreciated. This is the new function I am trying to run but keep getting error.

 

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']);

 

}

 

Many thanks

Link to comment
Share on other sites

Just some observations...

1. $HTTP_POST_VARS is deprecated - use $_POST

2. preg_replace takes 3 params - pattern, replacement, string - look at your code to be sue you don't have a typo

3. simply removing the @ will not solve your issue with email addresses

4. removing numbers might cause problems if - "We have 3 rooms for you to use"

 

Link to comment
Share on other sites

Just some observations...

1. $HTTP_POST_VARS is deprecated - use $_POST

2. preg_replace takes 3 params - pattern, replacement, string - look at your code to be sue you don't have a typo

3. simply removing the @ will not solve your issue with email addresses

4. removing numbers might cause problems if - "We have 3 rooms for you to use"

 

Could you please correct me where the error is? Thanks

Link to comment
Share on other sites

$string = $_POST['brief']; /* simply put the post variable into a string */
$pattern = "/\d|@/"; /* the forward slash starts and stops your pattern - the \d says any number. the pipe | says here is another 'item' in the pattern */
$replacement = ""; /* describes what you will be using to replace found items */
$brief = preg_replace($pattern, $replacement,$string); /* performs the replacement */
echo "Before: <br />" . $string . "<hr>"; /* these next two lines are just so you can test what has happened */
echo "After:<br />" . $brief;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.