Skip to content

Instantly share code, notes, and snippets.

@pjaudiomv
Last active April 13, 2020 13:55
Show Gist options
  • Save pjaudiomv/f72d8941286b08eaa7d723b99e3b57f5 to your computer and use it in GitHub Desktop.
Save pjaudiomv/f72d8941286b08eaa7d723b99e3b57f5 to your computer and use it in GitHub Desktop.
get jft into array
<?php
$xml = new DOMDocument();
$xml->validateOnParse = true;
$xml->loadHTML(file_get_contents('https://jftna.org/jft/'));
$xpath = new DOMXPath($xml);
$table = $xpath->query("//table")->item(0);
$rows = $table->getElementsByTagName("tr");
$jftKeys = array('date', 'title', 'page', 'quote', 'source', 'content', 'thought', 'copyright');
$jftArray = [];
$i = 0;
foreach ($rows as $row) {
$cells = $row->getElementsByTagName('td');
foreach ($cells as $cell) {
$jftArray[$jftKeys[$i]] = preg_replace('# {2,}#', ' ', str_replace(array("\r", "\n"), '', trim(utf8_encode($cell->nodeValue))));
}
$i++;
}
print_r($jftArray);
/* Returns Array (
[date] => April 12, 2020
[title] => The big picture
[page] => Page 106
[quote] => "All spiritual awakenings have some things in common. Common elements include an end to loneliness and a sense of direction in our lives."
[source] => Basic Text, p. 50
[content] => Some kinds of spiritual experiences take place when we confront something larger than we are. We suspect that forces beyond our understanding are operating. We see a fleeting glimpse of the big picture and find humility in that moment. Our journey through the Twelve Steps will bring about a spiritual experience of the same nature, only more profound and lasting. We undergo a continual process of ego-deflation, while at the same time we become more conscious of the larger perspective. Our view of the world expands to the point where we no longer possess an exaggerated sense of our own importance. Through our new awareness, we no longer feel isolated from the rest of the human race. We may not understand why the world is the way it is or why people sometimes treat one another so savagely. But we do understand suffering and, in recovery, we can do our best to alleviate it. When our individual contribution is combined with others, we become an essential part of a grand design. We are connected at last.
[thought] => Just for Today: I am but one person in the entire scheme of things. I humbly accept my place in the big picture.
[copyright] => Copyright (c) 2007-2020,  NA World Services, Inc. All Rights Reserved
) */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment