Jump to content

Replace using one array


Ollifi

Recommended Posts

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

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:

http://yourdomain.com/unsubscribe.php?email=something@yourdomain.com&auth=XXXX

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 thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.