How to find and replace multiple values ​​in a string with PHP

I build a template system that uses predetermined fields (named fields 1-10) and a corresponding form to exchange them with user form data. I played with preg_replace and str_replace, but I do not know how to properly implement this feature because I have never used it before.

The system basically works by first downloading a "template" which is an HTML character string formatted as follows.





In a separate function, I want to replace the values ​​& # 39; {field1} & # 39; and & # 39; {field2} & # 39; channels submitted via the user form.

Until now, I pull the data as shown below:

For the model:

$html = Templates::where('id', '=', $templateId)->get('html');

For form data:

$field1 = $request->input('field_1');
$field2 = $request->input('field_2');

I then want to do something like the code below, but I'm not sure of the syntax. Since I did not use preg_replace, I manually write each field from one to ten as separate functions.

Ideally, I would like to loop through each field from 1 to 10 to check if it appears in the $ html as 'field #'. if the field exists in the template, then replace it with the form's data and if it's not just ignore it. To save, rewrite the code for each separate field.

Replacement attempt in progress:

$htmlPrep =  preg_replace('{field1}', $field1, $html);
$htmlPrep =  preg_replace('{field2}', $field2, $html);

The reason for replacing these areas of the string in the function, rather than putting them in place in the view, is that the field1-10 system and the build system should primarily work for multiple models that will have any number of fields limited to and secondly, the $ htmlPrep variable containing the result of the combined data will not be rendered, but sent to an API with CSS code to generate and return an image.

Thus, the expected result (using "a" and "b" as user input form values) would be a new variable named $ htmlPrep which contains:





Thank you in advance.

g Suite Administrator – How can I replace the default Google Calendar settings for users so that they can edit and move meetings between our rooms?

Within our organization, we have four conference rooms currently configured as resources via GSuite for Business.

One of these rooms has become the recruiting / interview room. I would like to give our recruiting team priority access to this room, with the following basic rules:

  • If the room is not reserved, any user should be able to book it for an event.
  • If the room is reserved for an event, Recruitment should be able to modify the details of the event and move it to another room.
  • Other users should not be able to move or edit default events.

We have already configured where the rooms are configured as resources. We have also added calendaring to all rooms where "Make Changes and Manage Sharing" access is enabled. However, while they are able to see events they are not able to move an event in another room.

Someone has thoughts?

How to replace WordPress Native Player with Fluid Player?

I want to replace my video player WordPress Native (video player by default) by Fluid player, because I want to display VAST advertising on my videos. So, how to replace WordPress Native Video Player with Fluid Player?

I use a plugin that creates video posts and all videos are played in a native video player. It will be a very big update if wordpress updates its native video player with VAST Advertising technology …

Why do the Socialist Democrats want to replace the electoral college by the popular vote?

If we had a majority majority voting system rather than a community system, the largest cities in America, like NY, LA, Chicago, would be Liberal, but liberal, big cities like this one. This means that the Democrats are still leading the country and nobody can do it, because these cities are largely democratic. It is the EC that allows voters in Gilbert, Arizona or Divide, Colorado, to participate in elections and not be deprived of the right to vote.

They like to argue, so come up with a better candidate. But only twice in my life, almost 50 years ago, has there ever been a split between the popular vote – or the vote of popular places – and the Electora College vote, you know, the small towns and cities that are not New York and Los Angeles.

For example, there are 3,141 counties in the country. Some people say that Hillary has won 57 counties out of 3,141 and some people have won 487 counties. They make a lot of nonsense about "false news saying that there are only 57 counties". This is accidental. This is a red herring. Trump still won the rest. That's at the very least over 2600 counties across the United States. If we had a "popular vote" system, then 487 counties took precedence over the more than 2600 counties that anyone else wanted. In the end, it seems to me that the EC is a county-by-county system of "popular vote". And if you want to talk about a more acceptable candidate, this responsibility falls on both Democrats and Republicans. People did not like Hillary. She lost. Large. If she had been a better candidate, she would have won. The fact that she did not shout "presented a better candidate" and not "canceled almost 245 years of established law so that you do not have to work as hard".

It's nothing more than a game of power to gain power and stay in power. The EC is constitutional. To revoke it would be to cancel 245 years of law that works for whose benefit? Certainly not yours.

If I replace the battery of my phone plus 3, will this affect the data on my phone? And will the accelerated charge still work?

So, I've been using my one plus 3 for about 3 years now, and I wanted to replace the battery on it because the phone is still excellent and catchy, but dies pretty quickly because of the compromised battery life.

Can I replace my monitor with HoloLens?

I work as a software developer. Can I replace my monitor with HoloLens? I want to use the mouse and keyboard and use Linux with a traditional desktop environment.

Would it reduce eyestrain?

linux – Replace forbidden characters function check python

I have "blackbox" with the following python function code (without permission to change it):

def exec_ping():
    forbidden = ('&', ';', '-', '`', '||', '|')
    command = input('Enter an IP: ')
    for i in forbidden:
        if i in command:
            print('Invalid characters')
    os.system('ping ' + command)

I want to execute this function with the following command entry:

-c 1 localhost; whoami;

For this command to be running:

ping -c 1 localhost; whoami;

How can I get around the Prohibited Character Check? Can I use other characters / encoding?

design – Delete the user data or replace it with an empty resource?

Let's say we have a publicly open REST API that allows the user to manipulate data using POST, GET, and DELETE. The API is exposed via service A, which at the server level calls service B, where the core business logic is located.

We have recently discussed how we should handle deletion.

Approach 1: Service B must provide an explicit deletion API to Service A so that data can be deleted when the user requests deletion.

Approach 2: Another argument was that when the user requests the deletion, the service A can simply use the POST API provided by the B service to write "an empty resource". It would be the same as the deletion.

I expressed my discomfort with the second option, but I was not able to convince the group why the first option was better.

What are the advantages and disadvantages of two approaches?

bash – ECR – Replace a fixed menu image with the same tag name

Under the script:


build_and_store_in_ECR() {

    local BUILD_VERSION=26Jul2019-1
    local version=“1.0”

    docker build -f somedockerfile -t team/subteam:$version  .

    $(aws ecr get-login --profile someprofile --region us-east-1 --no-include-email)

    echo "Pushing deploy docker image"
    docker tag team/subteam:$version$version
    docker push$version


when ran for the first time,

stores the image with the required image URI ( and the name of the tag as 1.0

But on re-run,

we expect to overwrite the image if it is pushed with the same tag version.

But I see that the old image is not labeled, and then the new image is created with the same version (1.0)

How to replace the image with the same tag name? in ECR

database – Replace the content of several articles: Integrated video code (shortcode) with a new video player code

I have a wordpress site using an old video plugin called FLV Embed and I want to replace it with any new video player code or other video plugin shortcode.

Currently, this plugin uses this style of shortcode tag:

(flv:url width height) 

For example:

(flv: 650 400)

I started using the video player whose built-in code looks like this:

So, I will have to replace the new Brid code. The problem is that I have more than 400 publications with embedded videos, so I try to find an automated way to edit and replace the video player in all my publications.
I'm sure I'll need a script but I do not know how to do it.

I thought I would use Mysql's search and replace feature, but it would not work, as each video had a different ID / URL. So, I think I will have to create a script to catch the URL of Amazon S3 and generate the new code.

At this point, it does not matter if I will use a Brid video player or any other video player or plug-in.

Any idea about the appropriate and faster approach (programming language, plugins, etc.) will be appreciated.