Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is my echo'd PHP variable still producing nothing?
    text
    copied!<p>I recently was provided an excellent answer on how to handle extracting my URL from HTML content here:</p> <p><a href="https://stackoverflow.com/questions/2173541/extracting-context-from-a-set-point-in-the-middle-of-an-html-file">Extracting context from a set point in the middle of an HTML file</a></p> <p>But after implementing the code, I still show nothing from the echo call on the variable afterwards. I know if I echo get_the_content(), it shows the entire post body as it should, but maybe its not being handled properly by loadHTML()? I implemented the code as provided (which to my knowledge works perfectly aka no errors) and within the foreach loop assigned the extracted URL to a variable so I could use it in the location necessary, as shown by the code below:</p> <pre><code>&lt;?php $doc = new DOMDocument(); $doc-&gt;strictErrorChecking = FALSE; $xpath = new DOMXpath($doc); $a = 1; if (have_posts()) : while ( have_posts() ) : the_post(); ?&gt; &lt;div class="ORtrack"&gt; &lt;?php $success = $doc-&gt;loadHTML(get_the_content()); if ($success === FALSE) { // error handling } else { $hrefs = $xpath-&gt;query("//a[contains(@href,'mp3')]/@href"); foreach ($hrefs as $href) { $BEmp3s = $href; } }; ?&gt; &lt;script type="text/javascript"&gt; var myCP&lt;?php echo $a; ?&gt; = new CirclePlayer("#jquery_jplayer_&lt;?php echo $a; ?&gt;", { mp3: "&lt;?php echo $BEmp3s; ?&gt;" }, { cssSelectorAncestor: "#cp_container_&lt;?php echo $a; ?&gt;", volume: 0.5 }); &lt;/script&gt; .... &lt;?php endif; wp_reset_query(); ?&gt; &lt;/div&gt; </code></pre> <p>There is only ONE MP3 URL to grab per Post body and I always want the first one if for some reason there does end up being multiple MP3 URL's, so is it really necessary to build the array? What am I still missing and is this the most efficient manner to accomplish this?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload