I want to get a certain information of a website. The problem I'm facing is that this certain information is changing maybe a few times a day. This is because the content is dynamic.
The goal of my PHP script is to get the content (dynamic content from a database) in a PHP variable.
I've set up a codepen to show you what I mean: https://codepen.io/anon/pen/XEVpBo
The HTML from the codepen:
<div class="wrapper">
<div class="some_useless_div">
<p>Some useless text paragraph.</p>
<div id="another_useless_div">
<p>The actual important part is: SOME_DYNAMIC_TEXT what I want to put into a variable. The text around that dynamic text is static text and will not change.</p>
</div>
</div>
</div>
Currently, what I do to capture the information is to explode around the dynamic information:
$content = file_get_contents('https://codepen.io/anon/pen/XEVpBo');
$parts = explode('The actual important part is: ', $content); // some text that is left of the information.
$parts2 = explode(' what I want to put into a variable.', $parts[1]); // some text that is right of the information.
$information = $parts2[0]; // AHA! Now we have the information!
However, this really feels like spaghetti code. Isn't there a function that maybe searches for a string and returns that value such as:
$information = search_string('The actual important part is: %s what I want to put into a variable.');
where %s
would be the information put into the $information variable.
Again, the code I use (above) works but it really feels like bad code. I'm looking for a clean function of PHP.