troubleshooting Question

Match and Replace String with a certain pattern

Avatar of swhitlow
swhitlow asked on
PHP
17 Comments1 Solution254 ViewsLast Modified:
Hi! I have the following string:
$click = 'onclick="confirm_receipt(\'[@::example_id::@]\');"';

I need to replace the [@::example_id::@]  with the following:
$value['example_id'];

So, that the final string will actually be:
$click = 'onclick="confirm_receipt(\'' . $value['example_id'] . ' \');";

I know I will need to use reg expressions but am unfamiliar with them right now and need to get this answer quickly.  :)

Also, I will not know the value in the middle of the string that has the surrounding [@:: ::@]

I have just used these characters to identify the variable that needs replaced. The [@:: and the ::@] characters can all go away. I have just used these as placemarkers.

So, the 'example_id' could very well be 'contact_id' or something else. I just need to extract that out of the string and create the new string with the $value['id']

Thanks!
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 17 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 17 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros