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 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 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. 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 = "[email protected]"; $parts = explode("@",$addr) $revised_addr = ucfirst($parts[0]). "@". ucfirst($parts[1]); // concatenate parts echo $revised_addr; // [email protected] 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. 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. 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. 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 := '[email protected]'; 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().... 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. 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 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. Link to comment https://forums.phpfreaks.com/topic/61513-trimming-an-email-address/#findComment-329178 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.