Ollifi Posted May 29, 2011 Share Posted May 29, 2011 Hello, how could I do a replace using one array? Example: $changes = array( "{NAME}" => $name, "{CHANGED_PART}" => $desc, "{CHANGE_D}" => date("j"), "{CHANGE_M}" => date("n") ); And then I would want to replace all parts in the left with parts in the right inside a string.Is that possible ? thank you.. Quote Link to comment https://forums.phpfreaks.com/topic/237775-replace-using-one-array/ Share on other sites More sharing options...
mikesta707 Posted May 29, 2011 Share Posted May 29, 2011 So you need to replace instances of the array keys with their respective values in some string. Use the array_keys() function. Like so $string = "some string with some stuff in it..."; $changes = array(...);//your changes array $newString = str_replace($array_keys($changes), $changes, $string); hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/237775-replace-using-one-array/#findComment-1221872 Share on other sites More sharing options...
Ollifi Posted May 29, 2011 Author Share Posted May 29, 2011 Yes, thank you so much =) it helped Here´s other question: I´m creating a email unsubscribe feature. What confirmation I should use in the url that the link could only be accessed directly from the email message? The url should be like: http://yourdomain.com/unsubscribe.php?email=something@yourdomain.com&auth=XXXX What function I should use to generate the XXXX part ? Quote Link to comment https://forums.phpfreaks.com/topic/237775-replace-using-one-array/#findComment-1221875 Share on other sites More sharing options...
mikesta707 Posted May 29, 2011 Share Posted May 29, 2011 there are many ways to do this, but one of the most common way is to create an MD5 or Sha1 hash of something unique to each user in the database (like perhaps their username, or email address, assuming that these two things are unique to each user (and they should be)) Quote Link to comment https://forums.phpfreaks.com/topic/237775-replace-using-one-array/#findComment-1221878 Share on other sites More sharing options...
Ollifi Posted May 29, 2011 Author Share Posted May 29, 2011 ok, thank you for helping ! Quote Link to comment https://forums.phpfreaks.com/topic/237775-replace-using-one-array/#findComment-1221881 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.