replace ej: hotmail.com with @hotmail.com before insert
Moderator: General Moderators
replace ej: hotmail.com with @hotmail.com before insert
Ok..
I do not allow emails to be included in the text.
However there is always somebody that is trying to get around the issue.
So now my following problem.
They figured out that if they use addresshotmail.com is will still be inserted.
And in the output i only check if its written like address@hotmail.com
How can i replace addresshotmail.com with address@hotmail.com when its being inserted into the database. And ofcourse lots of other email address extensions.
I would also like to replace phone numbers. ( an integer longer than 3 would be sufficient ) Since there can be a age or experiance years specified in the text.
I do not allow emails to be included in the text.
However there is always somebody that is trying to get around the issue.
So now my following problem.
They figured out that if they use addresshotmail.com is will still be inserted.
And in the output i only check if its written like address@hotmail.com
How can i replace addresshotmail.com with address@hotmail.com when its being inserted into the database. And ofcourse lots of other email address extensions.
I would also like to replace phone numbers. ( an integer longer than 3 would be sufficient ) Since there can be a age or experiance years specified in the text.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Code: Select all
$string = "some text here and my email is joebloggshotmail.com - email me!";
$insert_version = preg_replace('/(\b\w*?)hotmail\.com\b/is', "$1@hotmail.com", $string);
echo $insert_version;
?>- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
I'd also do this too:
Code: Select all
$string = 'My address is joebloggs at hotmail.com';
$insert_version = preg_replace('/(\b\w*)\s*at\s*hotmail\.com\b/is', "$1@hotmail.com", $string);
Last edited by Chris Corbyn on Sun Apr 24, 2005 1:49 pm, edited 1 time in total.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
ol4pr0 wrote:ps: you have the answer on how to replace a digit longer than 3 integers ?
Code: Select all
$string = 'My cell mobile is 123456789, keep it!';
$insert_version = preg_replace('/\d{3}\d+/s', '********', $string);
echo $insert_version;http://www.regular-expressions.info/
http://www.perl.com/doc/manual/html/pod/perlre.html
so this would be fine..
Code: Select all
<?
$string = $row->text;
$search = array('/(\b\w*)\s*at\s*hotmail\.com\b/','/(\b\w*?)hotmail\.com\b/','/(\b\w*?)yahoo\.com\b/');
$replace = array("$1@hotmail.com","$1@hotmail.com","$1@yahoo.com","$1@yahoo.es")
echo $string;
?>- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
LOL... yeah (If you had put the preg_replace() in there, but i know that was just a typo :p)
On another note....
If you're using arrays like that, because they're replaced by the respective value in the other array, to avoid things getting mixed up do this.
I know it tedious when first written but all you have to do after that is add to the patterns array 
On another note....
If you're using arrays like that, because they're replaced by the respective value in the other array, to avoid things getting mixed up do this.
Code: Select all
//original => replace
$patterns = array (
'/(f)oo/' => "bar$1",
'/\w+(\d+)/' => "$1"
); //etc etc
//then:
$orignal = array();
$replace = array();
foreach ($patterns as $orig => $repl) {
$original[] = $orig;
$replace[] = $repl;
}
preg_replace($original, $replace, $string);
Last edited by Chris Corbyn on Sun Apr 24, 2005 2:03 pm, edited 2 times in total.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Small problem.
Output
Code: Select all
<?
$string = "addresshotmail.com - addressyahoo.com - addressyahoo.es --12345 -- 123 -- 12 -- 1234";
$patterns = array (
'/(\b\w*?)hotmail\b/' => "$1@hotmail",
'/(\b\w*?)yahoo\b/' => "$1@yahoo",
'/\d{3}\d+/s' => "<font color=\"red\">Números de teléfono borrado</font>",
'/\w+(\d+)/' => "$1");
$orignal = array();
$replace = array();
foreach ($patterns as $orig => $repl) {
$original[] = $orig;
$replace[] = $repl;
}
echo preg_replace($original, $replace, $string);
?>As you can see its dispaying 3 -- 2 instead of 123 -- 12address@hotmail.com - address@yahoo.com - address@yahoo.es --Número teléfono borrado -- 3 -- 2 -- Número teléfono borrado
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia