[nycphp-talk] Help trying to put email address into filename
Analysis & Solutions
danielc at analysisandsolutions.com
Thu Jun 12 02:39:42 EDT 2003
Phil:
On Wed, Jun 11, 2003 at 07:18:28PM -0400, soazine at pop.erols.com wrote:
>
> foreach (array('.', '_') as $key => $val) {
> $safeEmail = preg_replace("/\\\\$val/e", '%' . ord($val), $email); // YOU
> HAVE TO REPLACE . AND _ WITH ASCII NUMBERS
> }
I'm guessing the parse error is due to misusing the "e" modifier. But,
forget about that, since there are a bunch of other things awry here...
On a minor point, you don't need the $key, since you don't really care
about the key. You'd just need this:
foreach (array('.', '_') as $val) {
But, your approach is flawed, since you reassign the output to $safeEmail
from $email, $safeEmail will only have the replacements for the last
element in the input array. You'd need to use $email as both input and
output for this approach to work.
Finally, a simpler way to do what you're trying to do is via strtr(). For
efficiency sake, I reused $email.
$repl = array(
'.' => '%46',
'_' => '%95'
);
$email = strtr($email, $repl);
--Dan
--
FREE scripts that make web and database programming easier
http://www.analysisandsolutions.com/software/
T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
4015 7th Ave #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409
More information about the talk
mailing list