ozPATT Posted July 26, 2006 Share Posted July 26, 2006 Hi All, I have a CMS, where people enter information into a textarea, that gets inserted into a db. What I would like to do, is replace all email addresses, with a function that will mask the address, but to do that, i need to find a way to find the address to replace. I can find the @ easy enough, but I don't know how to get the whole address.Any help would be good. ThanksPatrick Quote Link to comment Share on other sites More sharing options...
redarrow Posted July 26, 2006 Share Posted July 26, 2006 This is a valadation email code you can use it to convert to what you want ok.[code]if(!eregi("^[a-z0-9_]+@[a-z0-9\-]+\.[a-z0-9\-\.]+$" ,$email)) {echo"please add a correct email address<br><a href='what_ever.php'>Please try agin!</a>";exit;[/code] Quote Link to comment Share on other sites More sharing options...
ozPATT Posted July 26, 2006 Author Share Posted July 26, 2006 sorry, must not have explained properly...I need to mask email addresses. So I have a function, that takes 2 arguments, the user and the domain. For every email address in a given text, i need to replace it with say, MaskEmail($email) - $email being the address... Quote Link to comment Share on other sites More sharing options...
zq29 Posted July 26, 2006 Share Posted July 26, 2006 You could do something like this:[code]<?phpfunction mask_email($email) { $patterns = array("/\./","/@/"); $replacements = array(" [dot] "," [at] "); return preg_replace($patterns, $replacements, $email);}echo mask_email("mail@somewhere.com");?>[/code][b]EDIT:[/b] I just re-read your post, and you want to know how to [i]find[/i] the email address in a block of text, right? How about this:[code]<?php$str = "Hello, my email address is mail@somewhere.com what is your email address? Is it somewhere@mail.com ?";preg_match_all("/[a-z0-9_]+@[a-z0-9\-]+\.[a-z0-9\-\.]+/",$str,$out);foreach($out[0] as $email) { $str = str_replace($email,mask_email($email),$str);}echo $str;?>[/code]An alternative option would be to use preg_replace() I guess, but I'm not that good at regex to offer a way of using it to the extent that you need to! Quote Link to comment Share on other sites More sharing options...
ozPATT Posted July 26, 2006 Author Share Posted July 26, 2006 haha, thanks again for the reply, but I think i am not being too clear... i have the function to mask the email, my problem is actually getting the email address from the text, as there may be several addresses in one section. So each address will need to be replaced, with the function call. if that makes sense., thanks for the prrompt replies though... Quote Link to comment Share on other sites More sharing options...
zq29 Posted July 26, 2006 Share Posted July 26, 2006 ^^ EDITED MY POST ABOVE ^^ Quote Link to comment Share on other sites More sharing options...
ozPATT Posted July 26, 2006 Author Share Posted July 26, 2006 ooh, that looks like it could be just the ticket... i will give that a try and let you know how i get on. thanks for that! woohoo!! worked! :o) thanks! Now I just need to work out another scripting problem, but perhaps you could help me with that too if you have time? My client needs to enter articles onto his site, done the same way. Currently, he includes some javascript that will open up a popup window, and show the user an image, stored in the popup directory. I need to find a way to incorporate this into the site, and I think a similar way would be good.What I am thinking, is if he was to put: [popup="image.jpg"] wherever he wanted these popups to go, then i just extract where it says the above, and take out what is in the quote marks. then replace, using the extracted as the href src or something like that. does that make sense? thanks for your help with the above again. :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.