For PostgreSQL: select substring(email from '^[^#]+') from test_email;
or, if you're updating the database: update test_email set email=substring(email from '^[^#]+'); Both of these solutions will out-perform marshalling the string in PHP and then manipulating it there, in the update case it is both safer and significantly more efficient against a large table. It's worth noting that the # character, along with many other unexpected characters, is technically valid in the local part (prior to the @) of an email address. In practice I'm not aware of any email hosts that allow that on a routine basis, but for security purposes it is unwise to put unencoded email addresses into delimited formats. Regards, Richard. On 14 May 2010 22:46, yeosteve <[email protected]> wrote: > Thanks, > > I've got a couple of students who are competing with each and me to > write the most efficient calls, and I'm anticipating their fisrt > question on Monday. Bit sad at this time on a Friday night ..... > > On May 14, 10:41 pm, Simon J Welsh <[email protected]> wrote: >> You could also use list($address) = explode('#', $innerRow >> ['PeopEmail']), which does the same thing as array_shift, but without >> an extra function call. >> >> No matter what you pick, it'll be either two inbuilt function calls or >> a language construct and an inbuilt function call, so you'll probably >> need a heck of a lot of iterations before you'll notice one being >> marginally faster than another. >> >> As for each one is better, that's totally a matter of taste. >> >> On 14/05/2010, at 10:33 PM, yeosteve wrote: >> >> >> >> >> >> > Hi >> >> > I have a field in a database with >> > [email protected]#mailto:[email protected]# . I want to reduce it >> > to just the email address. >> >> > Is is better/faster to use >> >> > substr($innerRow['PeopEmail'],0,strpos($innerRow['PeopEmail'],'#')) >> >> > or >> >> > array_shift(explode('#',$innerRow['PeopEmail'])) >> >> > Thanks >> >> > Steve >> >> --- >> Simon Welsh >> Admin ofhttp://simon.geek.nz/ >> >> Who said Microsoft never created a bug-free program? The blue screen >> never, ever crashes! >> >> http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e >> >> -- >> NZ PHP Users Group:http://groups.google.com/group/nzphpug >> To post, send email to [email protected] >> To unsubscribe, send email to >> [email protected] > > -- > NZ PHP Users Group: http://groups.google.com/group/nzphpug > To post, send email to [email protected] > To unsubscribe, send email to > [email protected] -- NZ PHP Users Group: http://groups.google.com/group/nzphpug To post, send email to [email protected] To unsubscribe, send email to [email protected]
