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 8328475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:27:23+00:00 2026-06-09T01:27:23+00:00

how can i get the attribute values for seconds using php: <yt:duration seconds=’12445’/> this

  • 0

how can i get the attribute values for seconds using php:

<yt:duration seconds='12445'/>

this is what i have done so far:

        $xmlstr  = file_get_contents($xml);
    $xml_content = new SimpleXMLElement($xmlstr); 
    echo $xml_content->xpath('//yt:duration')->attributes;
    print_r($xml_content->xpath('//yt:duration'));
    echo $xml_content->xpath('//yt:duration')->attributes()->seconds;

which displays these messages:

Notice: Trying to get property of non-object in C:\xampp\htdocs\ytm\xmlTest.php on line 22
Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [seconds] => 12445 ) ) ) 
Notice: Trying to get property of non-object in C:\xampp\htdocs\ytm\xmlTest.php on line 24

Notice: Trying to get property of non-object in C:\xampp\htdocs\ytm\xmlTest.php on line 24
  • 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-06-09T01:27:25+00:00Added an answer on June 9, 2026 at 1:27 am

    This:

    $xml_content->xpath('//yt:duration')
    

    Returns an array (as your print_r() will tell you). You’ll have to grab the first element (at index 0) in order to work with the SimpleXMLElement that corresponds to the <yt:duration> node:

    $list = $xml_content->xpath('//yt:duration');
    $node = $list[0];
    

    Then, you can get the attibutes with attributes():

    $attributes = $node->attributes();
    echo $attributes['seconds']; // Not 100% sure on this, might be $attributes->seconds
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a has_many :through form where I can't get an extra attribute to
I have an attribute declared on property. How can I get the property name
How can I ignore the attribute error I get when I issue this command?
Is there any attribute associated with the starting time I can get from the
How can I get all tr elements without id attribute? <tr id=name>...</tr> <tr>...</tr> <tr>...</tr>
Is it true that the WebInvoke attribute can take GET as a method? I
How can i create an attribute with a namespace? To get the following output?
I have one table having ID and other attributes. How can I get list
I need to find attribute values in an ASPX file using regular expressions. That
I'm using RSpec for tests and I don't know how to get this to

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.