phpprintingyamlfile-put-contents

How to omit/ignore tags like <br> when passing PHP content to a YAML file?


I want to 'print' the output of a PHP file into a YAML

My original PHP output looks like this:

enter image description here

, and goes on for 150 more blocks.

As you can see, it has the YAML file structure. I would like to print that output into the YAML file so that those 150 blocks are written like this:

  -
        ref: trade-67
        id: 67
        name: Plumber
        category: $trade-category-1
    -
        ref: trade-68
        id: 68
        name: Electrician
        category: $trade-category-2  
    -
#and so on...

Now, when I execute my PHP code using the file_put_contents($MyYamlFile, $PhpLoop) function, I obtain the following code in my YAML file:

    <br>-<br>    &nbsp;&nbsp;ref: trade-Ref: trade-id
    <br>    &nbsp;&nbsp;id: Trade-ID
    <br>    &nbsp;&nbsp;name: Trade Name

#150 times...

...as expected.

So, my question is: How can I omit tags like <BR> and &nbsp, and dump exactly what localhost ouputs in the previous image?

If not, is there any other better method you can recommend?


Solution

  • You need to use str_replace() along with strip_tags()

    something like:-

    strip_tags(str_replace("&nbsp;","",$string),"<br/>");