Jump to content

Replace using one array


Recommended Posts

Hello, how could I do a replace using one array?



$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..

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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:


What function I should use to generate the XXXX part ?

Link to comment
Share on other sites

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))

Link to comment
Share on other sites


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

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.