Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Which PHP replace function?


Acheron

Recommended Posts

Posted

I know general questions aren't often welcome or answered here but it doesn't hurt to try. :)

 

What would be the proper function and syntax to replace everything between the first X and the last Y with Z?

 

For example:

 

oneXtwoYthreeYfour

 

would become (hopefully)

 

oneXZYfour

 

 

TIA if anyone can help. :)

Posted

Well, I was able to do this but it's not quite what I wanted as it simply replaces everything after and including the "@"

 

substr($reviews['customers_email'], 0, strlen($reviews['customers_email'])-strlen (strstr ($reviews['customers_email'],"@")))

 

So "[email protected]" becomes "john" instead of "john@***.com" which is what I was shooting for.

Posted

Why not

$at_sign = strpos($reviews['customers_email'], '@');
$last_dot = strrpos($reviews['customers_email'], '.');
$obfuscated_email = substr($reviews['customers_email'], 0, $at_sign+1) . '***' . substr($reviews['customers_email'], $last_dot);

Hth,

Matt

Always back up before making changes.

Posted

Matt,

 

Because I couldn't quite get it right. hehe Thanks, will give that a go. Really appreciate the response. :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...