zonkd Posted July 24, 2007 Share Posted July 24, 2007 I've a list of email addresses that I want to publish on a website. I want to extract the name before "@", then split it into two, and cap the first letter of both. I plan to show the name and have it as a mailto with the address, of course, in an <a href> situation. Be very grateful for some guidance. Cheers all paul Quote Link to comment https://forums.phpfreaks.com/topic/61513-trimming-an-email-address/ Share on other sites More sharing options...
AndyB Posted July 24, 2007 Share Posted July 24, 2007 I want to extract the name before "@", then split it into two, and cap the first letter of both. The explode() function can split the string on @ into two array elements The ucfirst() function will convert the first letter of a string to upper case Quote Link to comment https://forums.phpfreaks.com/topic/61513-trimming-an-email-address/#findComment-306175 Share on other sites More sharing options...
zonkd Posted July 24, 2007 Author Share Posted July 24, 2007 Many thanks, AndyB. But wrapping it together is what confuses me. Quote Link to comment https://forums.phpfreaks.com/topic/61513-trimming-an-email-address/#findComment-306192 Share on other sites More sharing options...
AndyB Posted July 24, 2007 Share Posted July 24, 2007 $addr = "wombat@home.com"; $parts = explode("@",$addr) $revised_addr = ucfirst($parts[0]). "@". ucfirst($parts[1]); // concatenate parts echo $revised_addr; // Wombat@Home.com Quote Link to comment https://forums.phpfreaks.com/topic/61513-trimming-an-email-address/#findComment-306214 Share on other sites More sharing options...
zonkd Posted July 26, 2007 Author Share Posted July 26, 2007 Thanks very much, AndyB. Quote Link to comment https://forums.phpfreaks.com/topic/61513-trimming-an-email-address/#findComment-308036 Share on other sites More sharing options...
fenway Posted July 30, 2007 Share Posted July 30, 2007 Of course, you could do something similar on the sql side with some string functions, too. Quote Link to comment https://forums.phpfreaks.com/topic/61513-trimming-an-email-address/#findComment-311263 Share on other sites More sharing options...
zonkd Posted August 3, 2007 Author Share Posted August 3, 2007 Be very grateful if you would show me how, fenway. Quote Link to comment https://forums.phpfreaks.com/topic/61513-trimming-an-email-address/#findComment-315053 Share on other sites More sharing options...
fenway Posted August 10, 2007 Share Posted August 10, 2007 set @email := 'first@last.com'; select @email, SUBSTRING( @email, 1, INSTR(@email, '@' ) - 1 ) AS user, SUBSTRING_INDEX(@email,'@',-1) AS host It's a little ugly to then use another set of substring function to mimic ucfirst().... Quote Link to comment https://forums.phpfreaks.com/topic/61513-trimming-an-email-address/#findComment-320234 Share on other sites More sharing options...
zonkd Posted August 10, 2007 Author Share Posted August 10, 2007 Thanks very much, Fenway. I'll try it tonight. Much obliged to you. Quote Link to comment https://forums.phpfreaks.com/topic/61513-trimming-an-email-address/#findComment-320253 Share on other sites More sharing options...
zonkd Posted August 10, 2007 Author Share Posted August 10, 2007 Fenway, genius says the label. May I borrow a little of it, please? What I don't follow is how I would use this. I have a mysql select that puts the email address onto the page. Something like ... $result = mysql_query("SELECT email_address, etc etc FROM etc WHERE etc"); Where would your code go here, please? I know this is very basic, but I can't decide if you mean it should go round the record name or to be declared separately. Hopefully paul Quote Link to comment https://forums.phpfreaks.com/topic/61513-trimming-an-email-address/#findComment-320472 Share on other sites More sharing options...
fenway Posted August 20, 2007 Share Posted August 20, 2007 Try select email_address,, SUBSTRING( email_address, 1, INSTR(email_address, '@' ) - 1 ) AS user, SUBSTRING_INDEX(email_address,'@',-1) AS host FROM etc WHERE etc. Quote Link to comment https://forums.phpfreaks.com/topic/61513-trimming-an-email-address/#findComment-329178 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.