Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6817619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:04:40+00:00 2026-05-26T21:04:40+00:00

I recently was provided an excellent answer on how to handle extracting my URL

  • 0

I recently was provided an excellent answer on how to handle extracting my URL from HTML content here:

Extracting context from a set point in the middle of an HTML file

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:

<?php
    $doc   = new DOMDocument();
    $doc->strictErrorChecking = FALSE;
    $xpath = new DOMXpath($doc);

    $a = 1;
    if (have_posts()) :
        while ( have_posts() ) : the_post();
?>
<div class="ORtrack">
    <?php
        $success = $doc->loadHTML(get_the_content());
        if ($success === FALSE) {
            // error handling
        } else {
            $hrefs = $xpath->query("//a[contains(@href,'mp3')]/@href");
            foreach ($hrefs as $href) {
                $BEmp3s = $href;
            }
        };
    ?>
<script type="text/javascript">
    var myCP<?php echo $a; ?> = new CirclePlayer("#jquery_jplayer_<?php echo $a; ?>",
    {
        mp3: "<?php echo $BEmp3s; ?>"
    }, {
        cssSelectorAncestor: "#cp_container_<?php echo $a; ?>",
        volume: 0.5
    });
</script>
    ....
<?php
    endif;
    wp_reset_query();
?>
</div>

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:04:41+00:00Added an answer on May 26, 2026 at 9:04 pm

    If there’s only one MP3 being returned by your xpath, then don’t use a foreach loop. That’s overkill. A single item can be retrieved by doing

    $BEmp3s = $hrefs->item(0)
    

    and you can check if the xpath actually found anything via

    if ($hrefs->length > 0) { ... found something ... }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently asked a question here, and someone provided this answer: private void button1_Click(object
I recently switched over to using Janus from a custom set of vim plugins
So I've been dealing with several APIs recently provided by different software vendors for
Recently I was looking at some source code provided by community leaders in their
Recently two users of our software from the same company started experiencing random closures
I recently asked this question here and got some great answers! Custom SQL GROUP
I've recently set some coursework for some undergraduate students for which they have to
Recently I was trying for a company ‘x’. They sent me some set of
I recently downloaded the Java JNA from https://github.com/twall/jna/servlets/ProjectDocumentList?folderID=7408&expandFolder=7408&folderID=0 and tried using it. However, as
I recently asked a question about building a SOAP message using the java provided

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.