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

  • SEARCH
  • Home
  • 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 8304493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:51:44+00:00 2026-06-08T17:51:44+00:00

I use the following php code to get a random amount of URL’s form

  • 0

I use the following php code to get a random amount of URL’s form an xpath query:

@$dom = new DOMDocument();
@$dom->loadHTML( $rawPage );
@$xpath = new DOMXPath( $dom );
@$itemCells = $xpath->query( "//td[@width=120]/a" );

I need to pick a url randomly from that pool so I can visit it via cURL.

What I would like to do is get the count of how many URL’s are found so I can use that as the max in a rand( 0 , $itemCells->length )

However it tells me that $itemCell Cannot use object of type DOMNodeList as array and that my rand() rand() expects parameter 2 to be long, object given

Perhaps there is a better way to go about 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-06-08T17:51:46+00:00Added an answer on June 8, 2026 at 5:51 pm

    I suspect that since $length is a readonly property, you’d run into trouble passing it to a function. So, the solution is to save the $length value from a DOMNodeList to a local variable first, then call rand(), like so:

    $max = $itemCells->length; 
    $rand = rand( 0, $max);
    

    Then you should be able to do this to grab a random node from the list:

    $random_node = $itemCells->item( $rand);
    

    And from there, to grab the URL, you would do:

    $url = $random_node->attributes->getNamedItem("href")->nodeValue;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I use the following PHP code: $id = $_GET['page']; $page = include ($id.'.php');
I use JEditable for making edit field which following code: $(function() { $(.field).editable(http://localhost/index.php/welcome/update_record, {
OK, i was using following code to reverse a date to use in php
I have the following php code: index.php <?php spl_autoload_extensions(.php); spl_autoload_register(); use modules\standard as std;
I need help with the PHP code for the following: Get the text between
I use the following code to change the language in my website: <?php session_start();
I use the following PHP code to generate some JS and echo it in
Hello Sir i want send list of data to php server i use following
I am working on a PHP project. There, I often use following syntax to
I use the following the jquery statements to call my php controller function, it

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.