We've retired the forum in favor of GitHub Discussions.

New conversations can be started on GitHub. Existing conversations will remain for a while longer.

Head over to GitHub →

YAML write error funniness

Erin Dalzell May 7, 2015 by Erin Dalzell

The original YAML file:

---
city: Vancouver
country: Canada
name: foo
---
test content

The code to add some values:

            $document = explode('---', File::get($filename), 3);
            $content = $document[2];

            $yaml = YAML::parse($document[1]);

            $city = $yaml['city'];
            $country = $yaml['country'];

            $address = $geocoder->geocode($city . ',' . $country)->first();

            //now convert
            $yaml['where']['latitude'] = $address->getLatitude();
            $yaml['where']['longitude'] = $address->getLongitude();

            File::put($filename, File::buildContent($yaml, $content));

The YAML after:

---
city: Vancouver
country: Canada
name: foo
where:
  latitude: 49.2608944
  longitude: -123.1139383
---

test content

Where did the empty content line come from?

Answered by Erin Dalzell!
>>>>>>> Answered <<<<<<<
4 Replies
2 Followers